-
Notifications
You must be signed in to change notification settings - Fork 420
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
Use attname
to get pk value
#650
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #650 +/- ##
==========================================
+ Coverage 95.21% 95.29% +0.07%
==========================================
Files 31 31
Lines 1025 1041 +16
==========================================
+ Hits 976 992 +16
Misses 49 49 ☔ View full report in Codecov by Sentry. |
Thanks @evanandrews-xrd for this PR. It would be great to add a test for the change. it can be a small test only for |
I've added some tests, although looking at this further it might not be necessary to have https://docs.djangoproject.com/en/5.0/ref/models/instances/#the-pk-property The only difference now between If you'd prefer, we can probably just delete the method and use |
Thanks @evanandrews-xrd for the update and providing more information.
Then we need to catch |
Let me know if you are done with this PR. then we can merge it |
I've just added a couple of extra comments to include what I touched on above. Happy for you to merge when ready. Thanks! |
Thanks @evanandrews-xrd |
If a model's primary key is another model, the current implementation of
LogEntryManager._get_pk_value
will needlessly pull in the entire object only to extract its primary key and discard it. This change gets the primary key directly from the first object.The
attname
field isn't particularly well documented in Django, but it is briefly mentioned here.On the base
Field
class, it is the same asname
:https://github.com/django/django/blob/adae619426b6f50046b3daaa744db52989c9d6db/django/db/models/fields/__init__.py#L973-L974
Whereas for
ForeignKey
, it is{name}_id
:https://github.com/django/django/blob/adae619426b6f50046b3daaa744db52989c9d6db/django/db/models/fields/related.py#L1117-L1118
Happy to remove the
assert
if you'd prefer not to use it.