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

Not able to use camelCase in orderBy field #1491

Open
innateessence opened this issue Jan 13, 2024 · 3 comments
Open

Not able to use camelCase in orderBy field #1491

innateessence opened this issue Jan 13, 2024 · 3 comments
Labels

Comments

@innateessence
Copy link

innateessence commented Jan 13, 2024

Note: for support questions, please use stackoverflow. This repository's issues are reserved for feature requests and bug reports.

  • What is the current behavior?

I execute a query with these arguments:

{
  "first": 50,
  "kind": "QXNzZXRLaW5kOjMzZGYxZmNhLWI0NTAtNDcyZS05ZmYzLWI5NzcxZmYxMzlkMZ==",
  "after": null,
  "search": null,
  "orderBy": "fuelType"
}

and fuelType (which is fuelType as a JSON column in a Django DB)
gets converted to fuel_type before it reaches django's ORM.

The culprit is here: /usr/local/lib/python3.11/site-packages/graphene_django/filter/fields.py (line: 99) resolve_queryset()
On the version of graphene_django that I'm currently using (3.2.0).

telegram-cloud-photo-size-1-4974392837344963747-y

execute a query where orderBy has a value that is in camelCase

  • What is the expected behavior?
    I'd expect the naming convention not to cause such weird sorting behavior. (Or, at the least, give me an error telling me what is wrong and why I cannot use camelCase)

  • What is the motivation / use case for changing the behavior?
    Please either add errors or fix the bug

  • Please tell us about your environment:

    • Version:
    • Platform:

graphene-django = "==3.2.0"

  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)
@innateessence innateessence changed the title Not able to CamelCase in orderBy field Not able to camelCase in orderBy field Jan 13, 2024
@innateessence innateessence changed the title Not able to camelCase in orderBy field Not able to use camelCase in orderBy field Jan 13, 2024
@innateessence
Copy link
Author

innateessence commented Jan 13, 2024

Looks like this is indeed expected behavior, based on previously merged PRs addressing this in the past
#1054

@kiendang
Copy link
Collaborator

From a quick look there doesn't seem to be a quick fix for this.
One workaround is if you have access to and can change model class you can do

fuel_type = JSONField(..., db_column="fuelType")

@innateessence
Copy link
Author

innateessence commented Jan 13, 2024

From a quick look there doesn't seem to be a quick fix for this. One workaround is if you have access to and can change model class you can do

fuel_type = JSONField(..., db_column="fuelType")

In my case, I believe this won't work as the key fuelType is dynamically provided from a key from a JSONB field, which is pushed from an external codebase in charge of the data.

Any ideas in regards to bypassing the resolve_queryset function from executing?
I don't mind explicitly writing my own order_by functionality in Django's ORM outside of graphene-land.

Alternatively, it'd be nice if we could provide an optional override somehow to prevent this kind of behavior for codebases that have data that expect to perfor an order_by using a value in camelCase, possibly as a kwarg somewhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants