Opened 43 hours ago
Closed 28 hours ago
#36188 closed Bug (invalid)
Reverse lookups on OneToOneField not working?
Description ¶
This StackOverflow post shows a scenario where a OneToOneField
is filtered on top of another OneToOneField
. So for example with the following modeling:
class Switch(models.Model): fqdn = models.CharField(max_length=45, unique=True) class ConfigState(models.Model): switch = models.OneToOneField(Switch, models.CASCADE, db_column='switch', primary_key=True, related_name='config_state') class EdgeSwitch(models.Model): switch = models.OneToOneField(Switch, models.CASCADE, db_column='switch', primary_key=True, related_name='edge_switch')
The query EdgeSwitch.objects.filter(switch__config_state=1)
does (no longer) work. On Django-3.x it apparently worked.
Change History (5)
comment:2 by , 38 hours ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:3 by , 35 hours ago
Resolution: | → invalid |
---|---|
Status: | assigned → closed |
comment:4 by , 30 hours ago
Resolution: | invalid |
---|---|
Status: | closed → new |
I found the missing part: the Switch
model needs to have managed = False
. A bit curious that this has impact, so:
class Switch(models.Model): fqdn = models.CharField(max_length=45, unique=True) class Meta: managed = False
comment:5 by , 28 hours ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
I think I got it, the tables got an app_label
, but that was probably not registered.
Note:
See TracTickets
for help on using tickets.
I cannot reproduce the issue against main or
stable/5.1.x
with the following patch based on the provided modelsTabularUnified new file tests/ticket_36188/models.py
TabularUnified new file tests/ticket_36188/tests.py
Please re-open if you can provide a set of models that trigger a
FieldError
.