mirror of
https://github.com/django/django.git
synced 2024-12-22 09:05:43 +00:00
Fixed #35344, Refs #34838 -- Corrected output_field of resolved columns for GeneratedFields in aliased tables.
Thanks Simon Charette for the review.
This commit is contained in:
parent
425b26092f
commit
5f18021640
1
AUTHORS
1
AUTHORS
@ -508,6 +508,7 @@ answer newbie questions, and generally made Django that much better:
|
||||
Joe Topjian <http://joe.terrarum.net/geek/code/python/django/>
|
||||
Johan C. Stöver <johan@nilling.nl>
|
||||
Johann Queuniet <johann.queuniet@adh.naellia.eu>
|
||||
Johannes Westphal <jojo@w-hat.de>
|
||||
john@calixto.net
|
||||
John D'Agostino <john.dagostino@gmail.com>
|
||||
John D'Ambrosio <dambrosioj@gmail.com>
|
||||
|
@ -39,7 +39,7 @@ class GeneratedField(Field):
|
||||
return Col(self.model._meta.db_table, self, self.output_field)
|
||||
|
||||
def get_col(self, alias, output_field=None):
|
||||
if alias != self.model._meta.db_table and output_field is None:
|
||||
if alias != self.model._meta.db_table and output_field in (None, self):
|
||||
output_field = self.output_field
|
||||
return super().get_col(alias, output_field)
|
||||
|
||||
|
@ -21,3 +21,6 @@ Bugfixes
|
||||
* Fixed a bug in Django 5.0 that caused a migration crash on PostgreSQL 15+
|
||||
when adding a partial ``UniqueConstraint`` with ``nulls_distinct``
|
||||
(:ticket:`35329`).
|
||||
|
||||
* Fixed a crash in Django 5.0 when performing queries involving table aliases
|
||||
and lookups on a ``GeneratedField`` of the aliased table (:ticket:`35344`).
|
||||
|
@ -123,7 +123,12 @@ class BaseGeneratedFieldTests(SimpleTestCase):
|
||||
db_persist=True,
|
||||
)
|
||||
|
||||
col = Square._meta.get_field("area").get_col("alias")
|
||||
field = Square._meta.get_field("area")
|
||||
|
||||
col = field.get_col("alias")
|
||||
self.assertIsInstance(col.output_field, IntegerField)
|
||||
|
||||
col = field.get_col("alias", field)
|
||||
self.assertIsInstance(col.output_field, IntegerField)
|
||||
|
||||
class FloatSquare(Model):
|
||||
@ -134,7 +139,12 @@ class BaseGeneratedFieldTests(SimpleTestCase):
|
||||
output_field=FloatField(),
|
||||
)
|
||||
|
||||
col = FloatSquare._meta.get_field("area").get_col("alias")
|
||||
field = FloatSquare._meta.get_field("area")
|
||||
|
||||
col = field.get_col("alias")
|
||||
self.assertIsInstance(col.output_field, FloatField)
|
||||
|
||||
col = field.get_col("alias", field)
|
||||
self.assertIsInstance(col.output_field, FloatField)
|
||||
|
||||
@isolate_apps("model_fields")
|
||||
|
Loading…
Reference in New Issue
Block a user