-
Notifications
You must be signed in to change notification settings - Fork 26
Fix DurationField, IntegerField unique constraints for values < or > 32 bits #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
timgraham
wants to merge
4
commits into
mongodb:main
Choose a base branch
from
timgraham:integerfield-db-type
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+140
−7
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ef9ebdf
to
5f881bd
Compare
e201cbe
to
59904f4
Compare
timgraham
commented
Aug 7, 2025
@@ -33,7 +33,7 @@ jobs: | |||
uses: actions/checkout@v4 | |||
with: | |||
repository: 'mongodb-forks/django' | |||
ref: 'mongodb-5.2.x' | |||
ref: 'ints-as-long' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The branch contains backward incompatible changes to the test suite and will be merged to mongodb-5.2.x before this patch:
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py
index da9d190096..83aa4c531a 100644
--- a/tests/expressions/tests.py
+++ b/tests/expressions/tests.py
@@ -1760,10 +1760,8 @@ class ExpressionOperatorTests(TestCase):
Number.objects.filter(pk=self.n.pk).update(
integer=640 / F("integer"), float=42.7 / F("float")
)
- # Unlike SQL, MongoDB doesn't truncate decimals for integer division.
- self.assertEqual(
- Number.objects.get(pk=self.n.pk).integer, Approximate(15.238, places=3)
- )
+
+ self.assertEqual(Number.objects.get(pk=self.n.pk).integer, 15)
self.assertEqual(
Number.objects.get(pk=self.n.pk).float, Approximate(2.755, places=3)
)
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index 3e226cd6a3..2c3e26cfc6 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -553,9 +553,11 @@ class OperationTests(OperationTestBase):
self.assertTableExists("test_crmo_pony")
# Test constraint works
Pony = new_state.apps.get_model("test_crmo", "Pony")
- Pony.objects.create(pink=1, weight=4.0)
- Pony.objects.create(pink=1, weight=4.0)
- Pony.objects.create(pink=1, weight=6.0)
+ from bson import Int64
+
+ Pony.objects.create(pink=Int64(1), weight=4.0)
+ Pony.objects.create(pink=Int64(1), weight=4.0)
+ Pony.objects.create(pink=Int64(1), weight=6.0)
if connection.features.supports_partial_indexes:
with self.assertRaises(IntegrityError):
Pony.objects.create(pink=1, weight=7.0)
@@ -3640,16 +3642,18 @@ class OperationTests(OperationTestBase):
# cursor.execute("INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)")
# cursor.execute("DELETE FROM test_alunto_pony")
pony = connection.database["test_alunto_pony"]
- pony.insert_one({"pink": 1, "weight": 1.0})
- pony.insert_one({"pink": 1, "weight": 1.0})
+ from bson import Int64
+
+ pony.insert_one({"pink": Int64(1), "weight": 1.0})
+ pony.insert_one({"pink": Int64(1), "weight": 1.0})
pony.delete_many({})
# Test the database alteration
with connection.schema_editor() as editor:
operation.database_forwards("test_alunto", editor, project_state, new_state)
# cursor.execute("INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)")
- pony.insert_one({"pink": 1, "weight": 1.0})
+ pony.insert_one({"pink": Int64(1), "weight": 1.0})
with self.assertRaises(DuplicateKeyError):
- pony.insert_one({"pink": 1, "weight": 1.0})
+ pony.insert_one({"pink": Int64(1), "weight": 1.0})
# with atomic():
# cursor.execute(
# "INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)"
@@ -3664,8 +3668,8 @@ class OperationTests(OperationTestBase):
# cursor.execute("INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)")
# cursor.execute("INSERT INTO test_alunto_pony (pink, weight) VALUES (1, 1)")
# cursor.execute("DELETE FROM test_alunto_pony")
- pony.insert_one({"pink": 1, "weight": 1.0})
- pony.insert_one({"pink": 1, "weight": 1.0})
+ pony.insert_one({"pink": Int64(1), "weight": 1.0})
+ pony.insert_one({"pink": Int64(1), "weight": 1.0})
pony.delete_many({})
# Test flat unique_together
operation = migrations.AlterUniqueTogether("Pony", ("pink", "weight"))
Jibola
requested changes
Aug 7, 2025
f810e16
to
a92073f
Compare
Relational fields use the db_type of the related field.
a92073f
to
6a24003
Compare
Jibola
approved these changes
Aug 11, 2025
…32 bits Whether values less than or greater than 32 bits were problematic depends on the field.
6a24003
to
1002678
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Whether values less than or greater than 32 bits were problematic depends on the field.