mirror of
https://github.com/django/django.git
synced 2025-01-03 06:55:47 +00:00
Fixed #34858 -- Corrected resolving output_field for PositiveIntegerField.
Regression in 40b8a6174f
.
This commit is contained in:
parent
d797243663
commit
4de31ec680
1
AUTHORS
1
AUTHORS
@ -978,6 +978,7 @@ answer newbie questions, and generally made Django that much better:
|
|||||||
Tim Heap <tim@timheap.me>
|
Tim Heap <tim@timheap.me>
|
||||||
Tim McCurrach <tim.mccurrach@gmail.com>
|
Tim McCurrach <tim.mccurrach@gmail.com>
|
||||||
Tim Saylor <tim.saylor@gmail.com>
|
Tim Saylor <tim.saylor@gmail.com>
|
||||||
|
Toan Vuong <me@toanvuong.io>
|
||||||
Tobias Kunze <rixx@cutebit.de>
|
Tobias Kunze <rixx@cutebit.de>
|
||||||
Tobias McNulty <https://www.caktusgroup.com/blog/>
|
Tobias McNulty <https://www.caktusgroup.com/blog/>
|
||||||
tobias@neuyork.de
|
tobias@neuyork.de
|
||||||
|
@ -512,6 +512,25 @@ class Expression(BaseExpression, Combinable):
|
|||||||
|
|
||||||
_connector_combinations = [
|
_connector_combinations = [
|
||||||
# Numeric operations - operands of same type.
|
# Numeric operations - operands of same type.
|
||||||
|
# PositiveIntegerField should take precedence over IntegerField (except
|
||||||
|
# subtraction).
|
||||||
|
{
|
||||||
|
connector: [
|
||||||
|
(
|
||||||
|
fields.PositiveIntegerField,
|
||||||
|
fields.PositiveIntegerField,
|
||||||
|
fields.PositiveIntegerField,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
for connector in (
|
||||||
|
Combinable.ADD,
|
||||||
|
Combinable.MUL,
|
||||||
|
Combinable.DIV,
|
||||||
|
Combinable.MOD,
|
||||||
|
Combinable.POW,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
# Other numeric operands.
|
||||||
{
|
{
|
||||||
connector: [
|
connector: [
|
||||||
(fields.IntegerField, fields.IntegerField, fields.IntegerField),
|
(fields.IntegerField, fields.IntegerField, fields.IntegerField),
|
||||||
|
@ -34,6 +34,7 @@ from django.db.models import (
|
|||||||
Model,
|
Model,
|
||||||
OrderBy,
|
OrderBy,
|
||||||
OuterRef,
|
OuterRef,
|
||||||
|
PositiveIntegerField,
|
||||||
Q,
|
Q,
|
||||||
StdDev,
|
StdDev,
|
||||||
Subquery,
|
Subquery,
|
||||||
@ -2455,6 +2456,23 @@ class CombinableTests(SimpleTestCase):
|
|||||||
|
|
||||||
|
|
||||||
class CombinedExpressionTests(SimpleTestCase):
|
class CombinedExpressionTests(SimpleTestCase):
|
||||||
|
def test_resolve_output_field_positive_integer(self):
|
||||||
|
connectors = [
|
||||||
|
Combinable.ADD,
|
||||||
|
Combinable.MUL,
|
||||||
|
Combinable.DIV,
|
||||||
|
Combinable.MOD,
|
||||||
|
Combinable.POW,
|
||||||
|
]
|
||||||
|
for connector in connectors:
|
||||||
|
with self.subTest(connector=connector):
|
||||||
|
expr = CombinedExpression(
|
||||||
|
Expression(PositiveIntegerField()),
|
||||||
|
connector,
|
||||||
|
Expression(PositiveIntegerField()),
|
||||||
|
)
|
||||||
|
self.assertIsInstance(expr.output_field, PositiveIntegerField)
|
||||||
|
|
||||||
def test_resolve_output_field_number(self):
|
def test_resolve_output_field_number(self):
|
||||||
tests = [
|
tests = [
|
||||||
(IntegerField, AutoField, IntegerField),
|
(IntegerField, AutoField, IntegerField),
|
||||||
|
Loading…
Reference in New Issue
Block a user