Skip to content

Conversation

@grahamalama
Copy link
Contributor

This PR sets frozen=True on our Pydantic models to enforce "immutability". As immutable as you can get in Python, anyway.

This change actually didn't have much of an impact on our application code, which is good. Most of the changes involved our test code. These included:

  • instead of using a model instance as a fixture then modifying the data in the tests, use factories to create a model with the desired attributes directly in the tests
  • in instances where we used a factory without overriding any kwargs (e.g. bugzilla_webhook_factory()), use the fixture provided by pytest-factoryboy when registering the factory instead

@grahamalama grahamalama requested a review from a team as a code owner December 18, 2023 14:46
Copy link
Contributor

@alexcottner alexcottner left a comment

Choose a reason for hiding this comment

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

I dislike something about having a factory specifically for unit tests. Feels equivalent to unsprung weight for some reason. But I'm not sure what reasonable alternatives we'd have in this situation.

@grahamalama grahamalama changed the title Immutable models Mark all pydantic models as frozen Dec 18, 2023
@grahamalama grahamalama merged commit 217d736 into main Dec 18, 2023
@grahamalama grahamalama deleted the immutable-models branch December 18, 2023 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants