[Django] #33259: The `Model._meta.related_objects` is return different values between shell and from the request

37 views
Skip to first unread message

Django

unread,
Nov 2, 2021, 10:16:44 PM11/2/21
to django-...@googlegroups.com
#33259: The `Model._meta.related_objects` is return different values between shell
and from the request
-------------------------------------+-------------------------------------
Reporter: Hop Duong | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 3.0
layer (models, ORM) | Keywords: Model, Related
Severity: Normal | Objects
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I'm implementing caching for the Model and generating the cache key by the
Model related objects.

{{{
class CacheModel(models.Model):

@classmethod
def get_model_related_fields(cls):
return cls._meta.related_objects
}}}

I have noticed that this method returns different values when I run from
the Django `shell` and from the request. For example:

- From the shell
{{{
(<OneToOneRel: ai_api.leadextradata>, <ManyToOneRel: ai_api.leadsubitv>,
<ManyToOneRel: ai_api.attachment>, <ManyToOneRel: ai_api.leadnote>,
<ManyToOneRel: ai_api.sharingcandidate>, <OneToOneRel:
ai_api.employmentdata>, <OneToOneRel: ai_api.leadshortcodekeyword>,
<OneToOneRel: ai_api.leadschedulingsettings>, <OneToOneRel:
ai_api.employeeonboarding>, <ManyToOneRel: ai_api.leadschedulemessage>,
<OneToOneRel: ai_api.itvteam>, <ManyToOneRel:
ai_kb.clienttrainingmessage>, <OneToOneRel:
ai_reminders.convoreminderaudit>, <ManyToOneRel:
ai_campaign.campaigncontact>, <ManyToOneRel:
ai_ratings.ratingconversation>, <ManyToOneRel: ai_ratings.ratingresponse>,
<ManyToOneRel: ai_event.eventcandidate>, <ManyToOneRel:
ai_event.eventcandidatecheckin>, <OneToOneRel: ai_event.eventitvlead>,
<OneToOneRel: ai_event.eventregistration>, <OneToOneRel:
ai_event.eventregistrationschedulingsettings>, <ManyToOneRel:
ai_journeys.leadjourneyprogress>, <ManyToOneRel: ai_jobs.appliedjob>,
<ManyToOneRel: ai_alerts.leadwatcher>, <ManyToOneRel:
ai_conversation_flows.leadconvoflow>, <ManyToOneRel:
ai_conversation_flows.leadconvostage>, <ManyToOneRel: ai_meeting.meeting>,
<ManyToOneRel: ai_interview_prep.itvprepcandidate>, <ManyToOneRel:
ai_recorded_interview.recordeditvcandidate>, <ManyToOneRel:
ai_candidate_attributes.candidateattributes>, <ManyToOneRel:
ai_cms.dynamiccontentcandidate>, <OneToOneRel:
ai_candidate_profile.previousapplication>, <ManyToOneRel:
ai_candidate_profile.previousapplication>, <ManyToOneRel:
ai_conversations.conversationstage>, <ManyToOneRel:
ai_conversations.leadsatisfycondition>, <ManyToOneRel:
ai_conversations.leadvalidanswer>)
}}}

- From the request
{{{
(<OneToOneRel: ai_api.leadextradata>, <ManyToOneRel: ai_api.leadsubitv>,
<ManyToOneRel: ai_api.attachment>, <ManyToOneRel: ai_api.leadnote>,
<ManyToOneRel: ai_api.sharingcandidate>, <OneToOneRel:
ai_api.employmentdata>, <OneToOneRel: ai_api.leadshortcodekeyword>,
<OneToOneRel: ai_api.leadschedulingsettings>, <OneToOneRel:
ai_api.employeeonboarding>, <ManyToOneRel: ai_api.leadschedulemessage>,
<OneToOneRel: ai_api.itvteam>, <ManyToOneRel:
ai_kb.clienttrainingmessage>, <OneToOneRel:
ai_reminders.convoreminderaudit>, <ManyToOneRel:
ai_campaign.campaigncontact>, <ManyToOneRel:
ai_ratings.ratingconversation>, <ManyToOneRel: ai_ratings.ratingresponse>,
<ManyToOneRel: ai_event.eventcandidate>, <ManyToOneRel:
ai_event.eventcandidatecheckin>, <OneToOneRel: ai_event.eventitvlead>,
<OneToOneRel: ai_event.eventregistration>, <OneToOneRel:
ai_event.eventregistrationschedulingsettings>, <ManyToOneRel:
ai_journeys.leadjourneyprogress>, <ManyToOneRel: ai_jobs.appliedjob>,
<ManyToOneRel: ai_alerts.leadwatcher>, <ManyToOneRel:
ai_conversation_flows.leadconvoflow>, <ManyToOneRel:
ai_conversation_flows.leadconvostage>, <ManyToOneRel: ai_meeting.meeting>,
<ManyToOneRel: ai_interview_prep.itvprepcandidate>, <ManyToOneRel:
ai_recorded_interview.recordeditvcandidate>, <ManyToOneRel:
ai_candidate_attributes.candidateattributes>, <ManyToOneRel:
ai_cms.dynamiccontentcandidate>, <OneToOneRel:
ai_candidate_profile.previousapplication>, <ManyToOneRel:
ai_candidate_profile.previousapplication>, <ManyToOneRel:
ai_conversations.conversationstage>, <ManyToOneRel:
ai_conversations.leadsatisfycondition>, <ManyToOneRel:
ai_conversations.leadvalidanswer>, <ManyToOneRel:
ai_cms.intentcmsresponselogs>)
}}}

We have one more model `<ManyToOneRel: ai_cms.intentcmsresponselogs>` in
the request.

--
Ticket URL: <https://code.djangoproject.com/ticket/33259>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 2, 2021, 10:30:44 PM11/2/21
to django-...@googlegroups.com
#33259: The `Model._meta.related_objects` is return different values between shell
and from the request
-------------------------------------+-------------------------------------
Reporter: Hop Duong | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: Model, Related | Triage Stage:
Objects | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Hi, you'll have to debug the issue and explain why Django is at fault or
at least provide some minimal code to reproduce the issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/33259#comment:1>

Django

unread,
Nov 3, 2021, 2:14:30 AM11/3/21
to django-...@googlegroups.com
#33259: Model._meta.related_objects returns different values in shell and from the
request.

-------------------------------------+-------------------------------------
Reporter: Hop Duong | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution: needsinfo

Keywords: Model, Related | Triage Stage:
Objects | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => needsinfo


Comment:

Also, Django 3.0 is no longer supported so you need to reproduce this
issue with Django's `main` branch.

--
Ticket URL: <https://code.djangoproject.com/ticket/33259#comment:2>

Reply all
Reply to author
Forward
0 new messages