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

Fix: Relationships on subquery model. #1

Merged
merged 4 commits into from
May 21, 2024

Conversation

hvdklauw
Copy link
Contributor

It was using the field name instead of the field column which resulted in errors for related fields.

This way other related models work as excepted, but it will issue a query.

@hvdklauw
Copy link
Contributor Author

Hmm this actually breaks still on the ManyToOne relations...

@hvdklauw
Copy link
Contributor Author

hvdklauw commented May 14, 2024

Maybe change it to:

declared = {f.column for f in model._meta.get_fields() if f.concrete}

But that needs some tests.

@hvdklauw
Copy link
Contributor Author

Fixed it by adding a shelve model to keep books on, so that there is a non concrete manytomany field on the book model to throw the expected

@hvdklauw
Copy link
Contributor Author

Ugh, the other side of a manytomany is a concrete field with a column that isn't actually in the database. (default django user groups field)

Which is weird?
https://docs.djangoproject.com/en/5.0/ref/models/fields/#django.db.models.Field.concrete states that the concrete is there to define if there is a database column, which is what we want for this.

@bmispelon bmispelon force-pushed the fix_relationships branch from d887afc to 39394a5 Compare May 21, 2024 18:12
@bmispelon
Copy link
Owner

(I've merged black and isort support + CI so I took the liberty to rebase this branch, I hope that was ok)

@hvdklauw
Copy link
Contributor Author

No problem, seems I sort is failing, but no clear error. I'll have a look later when I have time.

@bmispelon
Copy link
Owner

No problem, seems I sort is failing, but no clear error. I'll have a look later when I have time.

I think it doesn't like the empty line you removed in testproject/testapp/models.py. Do you have an automatic isort in your text editor? Which config does that use?

@hvdklauw
Copy link
Contributor Author

I think I might have ruff configured with default settings, not sure and not at my dev laptop right now to check.

@bmispelon
Copy link
Owner

I think I'm going to make isort happy then merge this. Seems like a net positive.

@bmispelon bmispelon merged commit 5775496 into bmispelon:main May 21, 2024
2 checks passed
@bmispelon
Copy link
Owner

Thanks again for the contribution! 🚀

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

Successfully merging this pull request may close these issues.

2 participants