#27397: Querying with an integer larger than SQLite supports crashes with OverflowError -------------------------------------+------------------------------------- Reporter: Ramin Farajpour | Owner: Ramin Cami | Farajpour Cami Type: Bug | Status: assigned Component: Database layer | Version: 1.10 (models, ORM) | Severity: Normal | Resolution: Keywords: SQLite, Error | Triage Stage: Accepted Handling | Has patch: 0 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Ramin Farajpour Cami): final patch {{{ diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 499d27d..58049ed 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -668,7 +668,7 @@ class ModelAdmin(BaseModelAdmin): try: object_id = field.to_python(object_id) return queryset.get(**{field.name: object_id}) - except (model.DoesNotExist, ValidationError, ValueError): + except (model.DoesNotExist, ValidationError, ValueError, OverflowError): return None def get_changelist_form(self, request, **kwargs): diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index 66ad278..36c1351 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -325,8 +325,11 @@ class SQLiteCursorWrapper(Database.Cursor): if params is None: return Database.Cursor.execute(self, query) query = self.convert_query(query) - return Database.Cursor.execute(self, query, params) - + try: + return Database.Cursor.execute(self, query, params) + except OverflowError: + return None + def executemany(self, query, param_list): query = self.convert_query(query) return Database.Cursor.executemany(self, query, param_list) diff --git a/django/db/backends/sqlite3/operations.py b/django/db/backends/sqlite3/operations.py index 47a26b5..6404ea6 100644 --- a/django/db/backends/sqlite3/operations.py +++ b/django/db/backends/sqlite3/operations.py @@ -122,6 +122,8 @@ class DatabaseOperations(BaseDatabaseOperations): # Native sqlite3 cursors cannot be used as context managers. try: return cursor.execute(sql, params).fetchone() + except OverflowError: + return None finally: cursor.close() }}} usage : {{{ >>> User.objects.get(id=1111111111111111111111111111111111111111111111111111111111111111111111111111111111) Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Python27\lib\site-packages\django\db\models\query.py", line 385, in get self.model._meta.object_name DoesNotExist: User matching query does not exist. >>> User.objects.get(id=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111) Traceback (most recent call last): File "<console>", line 1, in <module> File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 85, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Python27\lib\site-packages\django\db\models\query.py", line 385, in get self.model._meta.object_name DoesNotExist: User matching query does not exist. >>> User.objects.filter(id=1111111111111111111111111111111111111111111111111111111111111111111111111111111111) <QuerySet []> >>> }}} -- Ticket URL: <https://code.djangoproject.com/ticket/27397#comment:26> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.0f19f28901f1d557a5701308eed2964b%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.