Opened 3 weeks ago

Last modified 2 weeks ago

#35958 closed Bug

Issue with the distinct() function when specifying a field to run it on — at Initial Version

Reported by: adofosam Owned by:
Component: Database layer (models, ORM) Version: 5.1
Severity: Normal Keywords: distinct
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When I attempt to run the following code, I get a error.

Code:
"""
user = User.objects.get(id=user_id)
list = List.objects.filter(user=user).order_by('email').distinct('email')
"""

Error (Context: my app is called "lists"):
"""
django.db.utils.ProgrammingError: SELECT DISTINCT ON expressions must match initial ORDER BY expressions
LINE 1: SELECT COUNT(*) FROM (SELECT DISTINCT ON ("lists_list"...
"""

I'm using a postgresql database and my list model is as follows:
"""
class EventList(models.Model): # List for Marketting

id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True)
user= models.ForeignKey(User, on_delete=models.CASCADE)
email = models.EmailField()

"""

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top