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

Standardize model __repr__ functions #1140

Merged
merged 12 commits into from
Jan 2, 2025
Merged

Standardize model __repr__ functions #1140

merged 12 commits into from
Jan 2, 2025

Conversation

michplunkett
Copy link
Collaborator

@michplunkett michplunkett commented Dec 20, 2024

Description of Changes

Addressed inconsistencies with the model __repr__ functions.

Mostly making this because this PR got a bit out of control: #1138

Tests and Linting

  • This branch is up-to-date with the develop branch.
  • pytest passes on my local development environment.
  • pre-commit passes on my local development environment.

@michplunkett michplunkett self-assigned this Dec 20, 2024
@michplunkett michplunkett marked this pull request as ready for review December 20, 2024 06:51
Copy link
Collaborator

@AetherUnbound AetherUnbound left a comment

Choose a reason for hiding this comment

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

Looks good but there are a few more inconsistencies that might be good to address I think!

OpenOversight/app/models/database.py Outdated Show resolved Hide resolved
OpenOversight/app/models/database.py Outdated Show resolved Hide resolved
OpenOversight/tests/test_models.py Outdated Show resolved Hide resolved
@michplunkett
Copy link
Collaborator Author

Thanks for the eye, @AetherUnbound! I'll address those tomorrow and get back to you when they're done.

@b-meson
Copy link
Member

b-meson commented Dec 27, 2024

I don't know enough about Python to feel super comfortable reviewing it so I'll let the rest of the reviewers weigh in!

Copy link
Collaborator

@sea-kelp sea-kelp left a comment

Choose a reason for hiding this comment

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

Other than the inconsistencies Madison pointed out, this looks good! If we're being pedantic, the Python spec technically says you should be able to instantiate the object by eval-ing the string returned by __repr__
https://docs.python.org/3/library/functions.html#repr

I also wonder if we could get these for free by just making our model classes dataclasses: https://docs.sqlalchemy.org/en/20/orm/dataclasses.html

@michplunkett
Copy link
Collaborator Author

These are all good comments, thank you!

Please excuse the delay in my response, I've been holday'ing. I'll take a look at the MappedAsDataclass class tomorrow. If we could remove the need to update the __repr__ function and always be up to spec, that feels like the right way to go. I'll ping y'all when I have an update in place. 🧐

@michplunkett
Copy link
Collaborator Author

michplunkett commented Jan 2, 2025

Looking at the changes needed to implement the MappedAsDataclass class, @sea-kelp, I am going to make these updates using two PRs:

  1. Update with the changes that @AetherUnbound pointed out.
  2. Update SQL Alchemy from 1.4.52 -> 2.x.y and then add the MappedAsDataclass addition.

@michplunkett michplunkett merged commit a6c54bc into develop Jan 2, 2025
3 checks passed
@michplunkett michplunkett deleted the db-odds-and-ends branch January 2, 2025 22:16
@michplunkett michplunkett mentioned this pull request Jan 2, 2025
3 tasks
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.

4 participants