-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Fixed #36580 -- Fixed constraint validation crash when condition uses a ForeignObject
.
#19798
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
Conversation
9f3971a
to
efb8415
Compare
efb8415
to
e6f16d2
Compare
ForeignObject
.
Thanks for the speedy work here @JaeHyuckSa, but I just triaged the ticket to needsinfo, so I think we need to close this for now. |
My mistake, reopening! I had forgotten to change |
buildbot, test on oracle. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @JaeHyuckSa. The constraint on the test model can't be created on Oracle:
django.db.utils.DatabaseError: ORA-00904: "COMPOSITE_PK_COMMENT"."USER_ID": invalid identifier
@felixxm have you seen this Oracle error before? If there's a workaround, it would be nice to avoid creating a separate test model just to skip a test on Oracle.
It means that Also, I wouldn't mix this with composite PK tests but add them to the |
50af1d7
to
9776e8f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Appreciate the help with this one @JaeHyuckSa! I have a few comments.
The current version works for me on Oracle 🤷 |
Thanks for checking. Might be a multi-column-only DDL issue then 😉 . |
Hi @JaeHyuckSa 👋 Thanks for pushing this forward. This is a release blocker for 6.0, so we need to clear it by the middle of next week. Do you anticipate having time to continue it this week? Thanks. |
Hi @jacobtylerwalls Jacob! |
a560e34
to
64e4c91
Compare
@jacobtylerwalls Hi Jacob Sorry for the delay in addressing this; I wasn’t able to keep up with the agreed timeline as a lot of work suddenly came in. I’ve applied the simpler review comments, and regarding the requested test code, would this level of coverage be appropriate? Currently, the tests are failing for another reason: as you mentioned, a performance regression is occurring because both fields are being checked, which triggers an error. I think we’ll need to resolve this by making use of field.local_related_fields. |
64e4c91
to
e103551
Compare
Thanks for the update. I'll pick it up from here later this afternoon. |
e103551
to
8a58630
Compare
@jacobtylerwalls Thank you for reviewing. I've applied the changes you suggested above. :) |
8a58630
to
26e7487
Compare
26e7487
to
e768d91
Compare
@charettes I took a stab at a simpler approach, how does it look? |
django/db/models/base.py
Outdated
else: | ||
value = getattr(self, field.attname) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we continue if the field is not concrete?
else: | |
value = getattr(self, field.attname) | |
elif field.concrete: | |
value = getattr(self, field.attname) | |
else: | |
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an idea for a test that would cover that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you'd have to test _get_field_expression_map
directly for it as we don't have a lot of non-concrete in core.
The only two I can think about are GenericForeignKey
and soon ManyToManyField
after #19602 lands. The idea is that for these fields getattr(self, field.attname)
could return a manager which is not suitable to be passed as the right-hand-side in a lookup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it. In that case let's add coverage via ManyToManyField on #19602. I'll leave a note.
value = tuple( | ||
getattr(self, from_field) for from_field in field.from_fields | ||
) | ||
if len(value) == 1: | ||
value = value[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This highlights were still missing proper handling for non-pk composite fields.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exactly -- I'll open a follow-up issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried to capture this in ticket-36611, but if you meant something else, let me know! 🙏
… a ForeignObject. Follow-up to e44e832. Refs #36222.
e768d91
to
0340c45
Compare
Thanks @JaeHyuckSa ⭐ |
Trac ticket number
ticket-36580
Checklist
main
branch.