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
fix: tiles object manager #13630
fix: tiles object manager #13630
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is way more obvious, with the small exception of including_soft_deleted
😅
posthog/models/dashboard_tile.py
Outdated
class DashboardTile(models.Model): | ||
objects = DashboardTileManager() | ||
including_soft_deleted = models.Manager() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, definitely not typical to have two managers on a model. Lots of redundancy. Can we maybe instead add a method like all_even_soft_deleted()
to DashboardTileManager()
? That'd be plain super().get_queryset()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm 🤔 I pretty much lifted this straight out of the docs https://docs.djangoproject.com/en/4.1/topics/db/managers/#modifying-a-manager-s-initial-queryset
How about rename to objects_including_soft_deleted
? That way as someone starts to type objects...
intellisense will show them there are two options?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh fair enough, looks like I skipped out on that part of the docs :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've not memorised the entire Django docs 🤯 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You bet I've used summaries for the boring required reading books in school
Problem
Since extending soft delete to dashboard tiles we've had to remember to exclude deleted tiles (which is easy to forget e.g. #13629)
It's also easy to cause N+1 by excluding or not when the ORM isn't expecting it
was stacked on top of #13629
Changes
ModelManager
onInsight
,Dashboard
, andDashboardTile
to always exclude soft-deleted modelsHow did you test this code?
running the tests, checking locally