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

Accessing local fields using qs.select_related_fields causes a confusing error #80

Open
jordaneb opened this issue Feb 3, 2023 · 0 comments

Comments

@jordaneb
Copy link
Member

jordaneb commented Feb 3, 2023

I accidentally misused this like qs.select_related before realising I was using the wrong function but the error I received was a bit confusing.

I was calling this with something like qs.select_related_fields('author') but this line

select_related(*{field.rpartition(LOOKUP_SEP)[0] for field in fields}),
calls rpartition() on it which splits on __. If there are no __ sequences found in the string then you end up with a tuple like ['', '', 'author'] and only the first field is used so the args passed down into the ORM produce an error along the lines of Field '' is not valid on model x.

I reckon the solution would be to iterate over fields and raise a ValueError with the names of any fields which don't contain the __ sequence in them with an error message that probably suggests that maybe qs.select_related is what the user intended to use

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

No branches or pull requests

1 participant