Skip to content

Commit

Permalink
Fix for decorators in StateBlocks (#1224)
Browse files Browse the repository at this point in the history
* Fix for decorators in StateBlocks

* Run black

* Add comment and add to reaction block

* Run black
  • Loading branch information
John Eslick authored Jul 20, 2023
1 parent 38b8333 commit a03ea47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion idaes/core/base/property_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,13 @@ def __getattr__(self, attr):
attr: an attribute to create and return. Should be a property
component.
"""
return build_on_demand(self, attr)
try:
# try the Pyomo Block's __getattr__ method first which will return
# decorators for creating components on the block (e.g. Expression,
# Constraint, ...).
return super().__getattr__(attr)
except AttributeError:
return build_on_demand(self, attr)

def calculate_scaling_factors(self):
super().calculate_scaling_factors()
Expand Down
8 changes: 7 additions & 1 deletion idaes/core/base/reaction_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,13 @@ def __getattr__(self, attr):
attr: an attribute to create and return. Should be a property
component.
"""
return build_on_demand(self, attr)
try:
# try the Pyomo Block's __getattr__ method first which will return
# decorators for creating components on the block (e.g. Expression,
# Constraint, ...).
return super().__getattr__(attr)
except AttributeError:
return build_on_demand(self, attr)

def calculate_scaling_factors(self):
super().calculate_scaling_factors()
Expand Down

0 comments on commit a03ea47

Please sign in to comment.