Code

Opened 2 years ago

Last modified 6 months ago

#18098 new Bug

order_with_respect_to should construct set_RELATED_order() method name from related_name

Reported by: pressureman Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: yes Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

If two identically named models in separate apps refer to a parent to the same parent model in their order_with_respect_to, only one set_RELATED_order() method is created on the parent model.

Attachments (1)

order_wrt.diff (1.2 KB) - added by pressureman 2 years ago.

Download all attachments as: .zip

Change History (6)

Changed 2 years ago by pressureman

comment:1 Changed 2 years ago by pressureman

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

This following situation would cause this problem to surface:

    class Device(models.Model):
        name = CharField(max_length=60, unique=True)
        ...
     
     
    # foo/models.py
    class ExpansionModule(models.Model):
        device = models.ForeignKey(Device, related_name='foo_expansionmodule_set')
        module_type = models.CharField(max_length=32, choices=EXPANSION_MODULE_CHOICES)
        ... # additional fields specific to foo
     
        class Meta:
            order_with_respect_to = 'device'
     
     
    # bar/models.py
    class ExpansionModule(models.Model):
        device = models.ForeignKey(Device, related_name='bar_expansionmodule_set')
        module_type = models.CharField(max_length=32, choices=EXPANSION_MODULE_CHOICES)
        ... # additional fields specific to bar
     
        class Meta:
            order_with_respect_to = 'device'

"Device" objects would only have the one set_expansionmodule_order() method.

comment:2 Changed 22 months ago by aaugustin

  • Triage Stage changed from Unreviewed to Design decision needed

The problem is valid. However the proposed solution doesn't guarantee backwards compatibility. I'm not sure of what we should do.

comment:3 Changed 22 months ago by anonymous

How about making the order_with_respect_to attribute either a model name string for backwards compatibility, or a two-tuple, containing the parent model, and a name to assign the relationship? It's perhaps not the most elegant, but would satisfy both requirements.

comment:4 Changed 12 months ago by aaugustin

  • Triage Stage changed from Design decision needed to Accepted

We're getting rid of the DDN state, and this is a valid problem.

comment:5 Changed 6 months ago by timo

  • Needs tests set
  • Patch needs improvement set

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as new
The owner will be changed from nobody to anonymous. Next status will be 'assigned'
as The resolution will be set. Next status will be 'closed'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.