Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions django/db/backends/base/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@ class BaseDatabaseFeatures:
# SQL to create a model instance using the database defaults.
insert_test_table_with_defaults = None

# Does the Round() database function round to even?
rounds_to_even = False

# A set of dotted paths to tests in Django's test suite that are expected
# to fail on this database.
django_test_expected_failures = set()
Expand Down
3 changes: 2 additions & 1 deletion tests/db_functions/comparison/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def test_cast_to_decimal_field(self):
),
).get()
self.assertEqual(float_obj.cast_f1_decimal, decimal.Decimal("-1.93"))
self.assertEqual(float_obj.cast_f2_decimal, decimal.Decimal("3.5"))
expected = "3.4" if connection.features.rounds_to_even else "3.5"
self.assertEqual(float_obj.cast_f2_decimal, decimal.Decimal(expected))
author_obj = Author.objects.annotate(
cast_alias_decimal=Cast(
"alias", models.DecimalField(max_digits=8, decimal_places=2)
Expand Down
3 changes: 2 additions & 1 deletion tests/db_functions/math/test_round.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def test_integer_with_negative_precision(self):
IntegerModel.objects.create(normal=365)
obj = IntegerModel.objects.annotate(normal_round=Round("normal", -1)).first()
self.assertIsInstance(obj.normal_round, int)
self.assertEqual(obj.normal_round, 370)
expected = 360 if connection.features.rounds_to_even else 370
self.assertEqual(obj.normal_round, expected)

def test_transform(self):
with register_lookup(DecimalField, Round):
Expand Down
Loading