-
Notifications
You must be signed in to change notification settings - Fork 14
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
Rule.filter() and distinct QuerySets #21
Comments
Hm. That's a good question. Without actually having seen your rule and the generated QuerySet object and resulting SQL, it sounds like this is one of those cases where our decades-long practice of shoehorning the relational model where it doesn't belong via ORMs is coming back to bite us! My gut suspicion is that Bridgekeeper probably should apply The other option is refactoring how relations work so that the generated SQL is more likely to use subqueries instead of Can you share more about your custom |
Hi Leigh, I've recently started working with Kye and we've hit this issue again (but slightly differently). In this instance, Kye's override of To provide some more context to how we encounter this problem (names are made up but this is the general idea): We have a model structure as follows, where
We then have a custom
where The permission itself is then defined as:
So we use Django groups as a way of defining a set of permissions, and associate a user with a group (and thus permissions) for a specific instance of a Our issues (in this case) stem from the fact that multiple I suspect this isn't just unique to this specific situation, but any rule check that flows through a many-to-many relationship that does not enforce unique constraints on the foreign keys in the through models? (although, our models are not actually using Django's m2m field for presumably historic reasons I'm not familiar with! But the way the foreign keys are defined I think effectively makes it a m2m relationship) Hopefully this helps to provide some insight into the issue we ran into. Do you have any thoughts on how bridgekeeper could be adapted to accommodate our scenario? P.S. It's probably worth mentioning we're still running on v0.8, but I don't think that |
Happy for Phil to speak on my behalf on this one. Cheers. |
I suspect that this may be a case of user error, but I will raise it here anyway.
I have a custom
Rule
, where I am overridingquery()
(as expected). I just ran into a bit of an unexpected production bug where anUpdateView
using Bridgekeeper'sQuerySetPermissionMixin
raisedMultipleObjectsReturned
. This was because the query built by myRule()
ended up returning duplicate records.I could override
get_queryset()
on my view, however this is slightly verbose for what will likely be a widespread issue given the nature of my Rule. I would need to apply this verbose override to a lot of views (or things that eventually make use ofQuerySet.get()
).Do you feel that a solution to this should be incorporated within Bridgekeeper itself? I am weary of the fact that
DISTINCT
is a potentially expensive operation that should not be blanket applied.In the meantime, I have overridden
filter()
(which the documentation explicitly tells you not to do) and added a.distinct()
there. In my circumstances, I was willing to take the performance hit, as non-distinct results are possible with every use of my Rule.The text was updated successfully, but these errors were encountered: