-
Notifications
You must be signed in to change notification settings - Fork 768
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
Enforcing default ordering is too invasive (Django model <model> has to have a default ordering to be used in a Connection.) #1521
Comments
@Flauschbaellchen did setting |
Hi @kiendang, I'm unsure if we are talking about the same :) When using It's also likely that I missed something - that actually another |
I see. Thanks for the clarification. Looks like setting |
@kiendang Sure, I can try to get something together. Can we talk about the general implementation first? Whenever a request is being processed, the ordering is checked:
Checking for unique keys is important as to only check for an order is not enough. Error or warning:
In this case, it is non-invasive and can be set to "error" in development and "warning" in production. Location for "ordering": class MyModelType(DjangoObjectType):
class Meta:
model = MyModel
ordering = ["name", "pk"] As even now, the developer could specify a non-unique ordering, the validation should still be executed as described above. What do you think? |
Hi. I'm currently upgrading a project and I encountered this issue. I think your considerations are valid and it would work as far as I can see, but the approach is a bit convoluted in my opinion. The most common case for me is that I don't have any ordering and don't need any. Do I have to specify something explicitly to suppress errors/warnings? So I don't think django-graphene should enforce default ordering at all, and maybe a warning might be already too much. Most DBs don't enforce ordering per default for good reasons; neither should the first layer on top of it (the model) per default. 95% of the time I don't need it. I admit that I personally had to learn about (not) ordering and pagination "the hard way", but it's a bit too much of a guardrail as of 3.2.1 and the suggestions here. Just my opinion; some of it based on what I see elsewhere (e.g. in the DBs as mentioned above). |
@oliverhaas I have the same opinion as you, as I've mentioned before:
I would be totally fine if the changes are rolled back alltogether and only within the doc mentioned that you need to remember to specify an ordering. However, trying to help those users is also fine with me, that's why I proposed the aforementioned solution which does not enforce any ordering by default - but yes, it would require some changes to the code and might be too complex to maintain. Your comparison with the database is very good. It's the same issue: The ordering is random, until you specify something and really care about it.... the DB does not error out or reminds you on every query that it might not be the results you actually wanted. 🤷 /cc @kiendang |
I'm currently running into this issue trying to make my (django.auth) User model visible via graphene. Is there a way to provide the ordering from within the Node or resolver function or do I need to change my project to a custom user model? |
@oliverhaas @Flauschbaellchen the rollback has already been merged into dev #1518. Can one of you (or anyone else) make a PR bump to 3.2.2 similar to #1512? I'll merge and make a new 3.2.2 release. |
* build: bump graphene-django from 3.1.5 to 3.2.0 * fix: Fixed header name * fix: Issue with 3.2.1 downgraded to 3.2.0. See: graphql-python/graphene-django#1521 --------- Co-authored-by: Jose Buitron <jose.buitron@gmail.com>
Since version 3.2.1 a default ordering is enforced for models.
First of all, I want to say that I run into the problem which the PR #1495 tries to fix several times so the change is high appreciated.
Previously, I resolved this by always let the client to choose the ordering (as the pagination is, in my optinion, more a frontend-related problem and nothing the backend should care about).
Enforcing the ordering on the model level with
Meta.ordering
has (IMO) some disadvantages:Additionally, the change feels more like a breaking change, as it requires the codebase to be adjusted.
For our own models, we had a base class which was adjusted in the following
But as we do not only use our own models for the API, we had the problem that for third-party models the same error occurs:
As said before, the intention of the change itself is high appriciated.
However, I would like to have a more non-invasive approach.
Would it be possible to just "fall back" to an ordering of
pk
in caseMeta
does not specify it in the context of theConnection
?Idk if this is something the user should be warned about or if it should be even be a setting the developer can adjust if it is "enforced", "fall-back-to-pk" or "silenced".
The text was updated successfully, but these errors were encountered: