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

Use update instead of assignment to set _charges #1069

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

ntBre
Copy link

@ntBre ntBre commented Oct 2, 2024

Description

Minor update to #1066 to include _charges in the model definition. I still don't know why this is required, but it seems to work in my local tests. I just realized that it might be necessary to do self._charges.clear() before self._charges.update() to avoid mixing charges. I read the if condition as len == 0 and ... instead of or, which could possibly allow update to be called on a dict already containing some charges.

Checklist

  • Add tests - should be covered by existing tests
  • Lint
  • Update docstrings - n/a

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.58%. Comparing base (360b60c) to head (1f9608e).
Report is 2 commits behind head on develop.

Additional details and impacted files

Comment on lines -115 to +114
self._charges = self._get_charges(include_virtual_sites=False)
self._charges.update(self._get_charges(include_virtual_sites=False))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ... makes a fair amount of sense to me, actually. I think in non-Pydantic world it's best practice to update a dict instead of re-assign it, but I'm also pretty sure something in Pydantic's magic machinery means just passing the return value of another function to an instance attribute gummed something up something.

Copy link
Member

@mattwthompson mattwthompson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mattwthompson mattwthompson merged commit bdd2177 into develop Oct 2, 2024
21 checks passed
@mattwthompson
Copy link
Member

I just realized that it might be necessary to do self._charges.clear() before self._charges.update() to avoid mixing charges.

For posterity, this was a Cassandra level of prescient. For some reason, no tests that existed before this PR were failing, but some tests added elsewhere (#1070) did break without clearing the cache at that point.

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

Successfully merging this pull request may close these issues.

2 participants