Opened 13 months ago
Last modified 10 months ago
#33945 assigned Bug
get_previous_in_order and get_next_in_order return incorrect data when objects is stored in non-default database
Reported by: | François Granade | Owned by: | Aryan Amish |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | 4.0 |
Severity: | Normal | Keywords: | |
Cc: | Wael Ramadan | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Using the a simple model with an order_with_respect_to
(slight variation of the models in https://github.com/django/django/blob/main/tests/multiple_database/models.py):
class Person(models.Model): name = models.CharField(max_length=100, unique=True) class Pet(models.Model): name = models.CharField(max_length=100) owner = models.ForeignKey(Person, models.CASCADE) class Meta: order_with_respect_to = "owner"
then adding some object, and declaring an order for the pets:
human = Person.objects.using("other").create(name="Human") dog = Pet.objects.using("other").create(name="Dog", owner=human) cat = Pet.objects.using("other").create(name="Cat", owner=human) duck = Pet.objects.using("other").create(name="Duck", owner=human) human.set_pet_order([duck.pk, dog.pk, cat.pk], "other")
Then simply trying to get the previous or next pet will fail:
>>> dog.get_next_in_order() # would expect `cat` models.Pet.DoesNotExist: Pet matching query does not exist. >>> dog.get_previous_in_order() # would expect `duck` models.Pet.DoesNotExist: Pet matching query does not exist.
Change History (11)
comment:1 Changed 13 months ago by
Cc: | Wael Ramadan added |
---|---|
Owner: | changed from nobody to Wael Ramadan |
Status: | new → assigned |
comment:2 Changed 13 months ago by
Triage Stage: | Unreviewed → Accepted |
---|
comment:3 Changed 12 months ago by
This seems to be working correctly in Django 4.1.2
Tested with both default
and other
database.
comment:4 Changed 12 months ago by
Has patch: | set |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
comment:5 Changed 11 months ago by
Has patch: | unset |
---|---|
Resolution: | fixed |
Status: | closed → new |
If that's the case, you should identify the commit that fixed the issue. The test that Carlton wrote in comment 2 still fails on the main and stable/4.1.x branches, so I have my doubts this is fixed.
comment:6 follow-up: 8 Changed 11 months ago by
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Using Django 4.1.1 this does actually fail. Yet when using Django 4.1.2 this works perfectly. Yet looking at the Release notes (https://docs.djangoproject.com/en/4.1/releases/4.1.2/) there seems to be no mention of this ticket.
This has to be investigated as to what fixed the issue!
comment:7 Changed 11 months ago by
Resolution: | worksforme |
---|---|
Status: | closed → new |
comment:8 follow-up: 9 Changed 11 months ago by
Replying to Wael Ramadan:
This has to be investigated as to what fixed the issue!
It fails for me on the main
branch, stable/4.1.x
branch, and with 4.1.2
version so it's definitely not fixed.
comment:9 follow-up: 10 Changed 11 months ago by
Replying to Mariusz Felisiak:
Replying to Wael Ramadan:
This has to be investigated as to what fixed the issue!
It fails for me on the
main
branch,stable/4.1.x
branch, and with4.1.2
version so it's definitely not fixed.
How is that possible that it fails on 4.1.2
what type of database are you using?
comment:10 Changed 11 months ago by
Replying to Wael Ramadan:
Replying to Mariusz Felisiak:
Replying to Wael Ramadan:
This has to be investigated as to what fixed the issue!
It fails for me on the
main
branch,stable/4.1.x
branch, and with4.1.2
version so it's definitely not fixed.
How is that possible that it fails on
4.1.2
what type of database are you using?
OK, oddly enough purged everything and started from scratch using 4.1.2
and it does fail.
comment:11 Changed 10 months ago by
Owner: | changed from Wael Ramadan to Aryan Amish |
---|---|
Status: | new → assigned |
OK, I think this is valid.
Model._get_next_or_previous_in_order()
doesn't applyusing()
at all. srcReproduces with the following diff:
Let's accept to investigate.