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

Fixed #30427, Fixed #16176 -- Corrected setting descriptor in Field.contribute_to_class(). #14508

Merged
merged 2 commits into from Jun 15, 2021

Conversation

carltongibson
Copy link
Member

@carltongibson carltongibson commented Jun 9, 2021

Replaces #11337.

Updates, and puts the tests in place that were hanging from the previous PR. It's difficult to follow so I've commented hoping to make them clear (for now and the next poor soul coming back to this 😀)

We had release notes in an earlier version 5fc4884 — those were incorrect since the multiple inheritance example never worked. See 4bbe826.

The change in behaviour proposed is allowing that structure. See the adjustment in the (now named) test_multiple_inheritance_allows_inherited_field method.

Inheritance works ≈as expected except for the depth-first resolution in diamond-shaped cases. Calling that out in docs/topics/db/models.txt is I think probably worth while. I need to think about exactly where to put that/what to say. Input welcome. 😜

Comment on lines +1215 to +1216
# Override related field accessor.
Model.fk_id = property(lambda self: 'ERROR')
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you can't make this clash via @property any more, is the check still valid? Or at least could the error message and/or test model be changed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've pushed a second commit removing this test.

Not 100% convinced...

We (@felixxm) discussed previously on the original PR. IIRC we said we'd leave it, and maybe adjust to add a check going the other way. (i.e. Cover I tried to define the pk_id property, but it got overridden vs the previous Because I'd defined the property the field descriptor wasn't set.)

I'd like to address that as a separate cleanup ticket.

  • This has been going on too long already.
  • And there are real issues being fixed here vs a system check/config error.

🤔

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay fine by me, as long as the ticket exists :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created follow-up at ticket-32847

(Will leave this conversation unresolved so folks maybe see it as they're browsing.)

tests/model_inheritance/tests.py Outdated Show resolved Hide resolved
@adamchainz
Copy link
Sponsor Member

Calling that out in docs/topics/db/models.txt is I think probably worth while. I need to think about exactly where to put that/what to say.

Yes definitely. Perhaps just a really terse description is enough...

Fields attach descriptors to every model class that includes them.
Because of this, diamond inheritance will cause a leaf model to inherit fields depth-first rather than breadth-first.

For anyone attempting diamond inheritance (certainly a small minority) this note may be enough (?). I don't think a long section with diagrams is warranted, given the rarity.

@carltongibson carltongibson force-pushed the pr/11337-redux branch 2 times, most recently from 3e1cb4d to 34937aa Compare June 9, 2021 18:27
@carltongibson
Copy link
Member Author

I added a small note to the docs.

docs/topics/db/models.txt Show resolved Hide resolved
Comment on lines +1215 to +1216
# Override related field accessor.
Model.fk_id = property(lambda self: 'ERROR')
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay fine by me, as long as the ticket exists :)

Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carltongibson Thanks for pushing this to the finish line 🏁

@jarekwg Thanks for all your efforts 🥇

@adamchainz Thanks for reviews 🕵️

@carltongibson
Copy link
Member Author

Thanks both. I'll tidy this up and pull it in.

(What a set of tickets 😅)

…ontribute_to_class().

Co-authored-by: Jarek Glowacki <jarekwg@gmail.com>
@randykleinman
Copy link

Will this be backported to 3.2.x?

@adamchainz
Copy link
Sponsor Member

No, the backport policy only allows “Security fixes and data loss bugs” for a feature change like this: https://docs.djangoproject.com/en/dev/internals/release-process/#supported-versions .

@randykleinman
Copy link

Ok, thanks!

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