Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smart defaults not applied to Field cached attributes #67

Open
mbarlow12 opened this issue Mar 12, 2025 · 0 comments
Open

Smart defaults not applied to Field cached attributes #67

mbarlow12 opened this issue Mar 12, 2025 · 0 comments

Comments

@mbarlow12
Copy link
Collaborator

mbarlow12 commented Mar 12, 2025

Since Field:cache_attributes is called at initialization, all attributes defined on self in that method aren't updated in the call to SmartDefault:apply.

I've confirmed this by investigating the following from within Field:run after Field:finalize_process_graph is called:

$> self.attr('num_prod_wells') # result of the smart default for 'num_prod_wells'
  > <Quantity(10449, 'dimensionless')>
$> self.num_prod_wells
  > <Quantity(24.0, 'dimensionless')>

Thus, any process that references a property on the Field object won't be reading the updated value.

The fix is pretty small: call Field:cache_attributes immediately after SmartDefault.apply_defaults(). This would update all the direct references found in the codebase.

EDIT: All children of the field call cache_attributes before the smart defaults are applied, so their properties retain the original default values. Options for fixes:

  • no properties are directly referenced, update all instances of attr_object.some_attribute to attr_object.attr('some_attribute')
  • use @property (reference) to always fetch a computed value
  • leverage __getattr__ and or __getattribute__ to forward arbitrary property access to the field object

For the latter 2, there would still be ways to cache the values if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant