Skip to content

Commit

Permalink
Merge pull request #2857 from bagerard/remove_longfield
Browse files Browse the repository at this point in the history
remove longfield
  • Loading branch information
bagerard authored Oct 2, 2024
2 parents ea4e719 + 52007ed commit 8551738
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 82 deletions.
1 change: 0 additions & 1 deletion docs/apireference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ Fields
.. autoclass:: mongoengine.fields.EmailField
.. autoclass:: mongoengine.fields.EnumField
.. autoclass:: mongoengine.fields.IntField
.. autoclass:: mongoengine.fields.LongField
.. autoclass:: mongoengine.fields.FloatField
.. autoclass:: mongoengine.fields.DecimalField
.. autoclass:: mongoengine.fields.Decimal128Field
Expand Down
4 changes: 2 additions & 2 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ Development
- make sure to read https://www.mongodb.com/docs/manual/core/transactions-in-applications/#callback-api-vs-core-api
- run_in_transaction context manager relies on Pymongo coreAPI, it will retry automatically in case of `UnknownTransactionCommitResult` but not `TransientTransactionError` exceptions
- Using .count() in a transaction will always use Collection.count_document (as estimated_document_count is not supported in transactions)
- Further to the deprecation warning, remove ability to use an unpacked list to `Queryset.aggregate(*pipeline)`, a plain list must be provided instead `Queryset.aggregate(pipeline)`, as it's closer to pymongo interface
- Further to the deprecation warning, remove `full_response` from `QuerySet.modify` as it wasn't supported with Pymongo 3+
- BREAKING CHANGE: Further to the deprecation warning, remove ability to use an unpacked list to `Queryset.aggregate(*pipeline)`, a plain list must be provided instead `Queryset.aggregate(pipeline)`, as it's closer to pymongo interface
- BREAKING CHANGE: Further to the deprecation warning, remove `full_response` from `QuerySet.modify` as it wasn't supported with Pymongo 3+
- Fixed stacklevel of many warnings (to point places emitting the warning more accurately)
- Add support for collation/hint/comment to delete/update and aggregate #2842
- BREAKING CHANGE: Remove LongField as it's equivalent to IntField since we drop support to Python2 long time ago (User should simply switch to IntField) #2309
Expand Down
1 change: 0 additions & 1 deletion docs/guide/defining-documents.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ are as follows:
* :class:`~mongoengine.fields.ImageField`
* :class:`~mongoengine.fields.IntField`
* :class:`~mongoengine.fields.ListField`
* :class:`~mongoengine.fields.LongField`
* :class:`~mongoengine.fields.MapField`
* :class:`~mongoengine.fields.ObjectIdField`
* :class:`~mongoengine.fields.ReferenceField`
Expand Down
9 changes: 0 additions & 9 deletions mongoengine/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import pymongo
from bson import SON, Binary, DBRef, ObjectId
from bson.decimal128 import Decimal128, create_decimal128_context
from bson.int64 import Int64
from pymongo import ReturnDocument

try:
Expand Down Expand Up @@ -68,7 +67,6 @@
"URLField",
"EmailField",
"IntField",
"LongField",
"FloatField",
"DecimalField",
"BooleanField",
Expand Down Expand Up @@ -367,13 +365,6 @@ def prepare_query_value(self, op, value):
return super().prepare_query_value(op, int(value))


class LongField(IntField):
"""64-bit integer field. (Equivalent to IntField since the support to Python2 was dropped)"""

def to_mongo(self, value):
return Int64(value)


class FloatField(BaseField):
"""Floating point number field."""

Expand Down
23 changes: 23 additions & 0 deletions tests/fields/test_int_field.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from bson import Int64

from mongoengine import *
from tests.utils import MongoDBTestCase
Expand Down Expand Up @@ -42,3 +43,25 @@ class TestDocument(Document):

assert 1 == TestDocument.objects(int_fld__ne=None).count()
assert 1 == TestDocument.objects(int_fld__ne=1).count()

def test_int_field_long_field_migration(self):
class DeprecatedLongField(IntField):
"""64-bit integer field. (Equivalent to IntField since the support to Python2 was dropped)"""

def to_mongo(self, value):
return Int64(value)

class TestDocument(Document):
long = DeprecatedLongField()

TestDocument.drop_collection()
TestDocument(long=10).save()

v = TestDocument.objects().first().long

# simulate a migration to IntField
class TestDocument(Document):
long = IntField()

assert TestDocument.objects(long=10).count() == 1
assert TestDocument.objects().first().long == v
69 changes: 0 additions & 69 deletions tests/fields/test_long_field.py

This file was deleted.

0 comments on commit 8551738

Please sign in to comment.