Opened 21 months ago

Closed 21 months ago

Last modified 21 months ago

#34443 closed Bug (fixed)

Filtering reverse relations against invalid lookups crashes.

Reported by: Mariusz Felisiak Owned by: Mariusz Felisiak
Component: Database layer (models, ORM) Version: 4.2
Severity: Release blocker Keywords:
Cc: Simon Charette, David Wobrock Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Filtering reverse relations against invalid lookups crashes.

from django.db import models


class Author(models.Model):
    name = models.CharField(max_length=10)

class Report(models.Model):
    name = models.CharField(max_length=10)
    creator = models.ForeignKey(Author, models.CASCADE)

>>> Author.objects.filter(report__title="first")
...
  File "/django/django/db/models/expressions.py", line 380, in get_transform
    return self.output_field.get_transform(name)
AttributeError: 'ManyToOneRel' object has no attribute 'get_transform'

In Django 4.1 it raises django.core.exceptions.FieldError: Related Field got invalid lookup: title.

Regression in ce6230aa976e8d963226a3956b45a8919215dbd8.

Change History (4)

comment:1 by Carlton Gibson, 21 months ago

Triage Stage: UnreviewedAccepted

comment:2 by Mariusz Felisiak, 21 months ago

Has patch: set

comment:3 by GitHub <noreply@…>, 21 months ago

Resolution: fixed
Status: assignedclosed

In 996c8022:

Fixed #34443 -- Fixed filtering by transforms on reverse relations.

Regression in ce6230aa976e8d963226a3956b45a8919215dbd8.

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 21 months ago

In f12dc36:

[4.2.x] Fixed #34443 -- Fixed filtering by transforms on reverse relations.

Regression in ce6230aa976e8d963226a3956b45a8919215dbd8.
Backport of 996c802229b93fe83c39842e56c6b8668464deaf from main

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