Python django.db.utils.NotSupportedError() Examples
The following are 30
code examples of django.db.utils.NotSupportedError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.db.utils
, or try the search function
.
Example #1
Source File: utils.py From bioforum with MIT License | 6 votes |
def callproc(self, procname, params=None, kparams=None): # Keyword parameters for callproc aren't supported in PEP 249, but the # database driver may support them (e.g. cx_Oracle). if kparams is not None and not self.db.features.supports_callproc_kwargs: raise NotSupportedError( 'Keyword parameters for callproc are not supported on this ' 'database backend.' ) self.db.validate_no_broken_transaction() with self.db.wrap_database_errors: if params is None and kparams is None: return self.cursor.callproc(procname) elif kparams is None: return self.cursor.callproc(procname, params) else: params = params or () return self.cursor.callproc(procname, params, kparams)
Example #2
Source File: schema.py From bioforum with MIT License | 6 votes |
def alter_db_table(self, model, old_db_table, new_db_table, disable_constraints=True): if model._meta.related_objects and disable_constraints: if self.connection.in_atomic_block: raise NotSupportedError(( 'Renaming the %r table while in a transaction is not ' 'supported on SQLite because it would break referential ' 'integrity. Try adding `atomic = False` to the Migration class.' ) % old_db_table) self.connection.enable_constraint_checking() super().alter_db_table(model, old_db_table, new_db_table) self.connection.disable_constraint_checking() else: super().alter_db_table(model, old_db_table, new_db_table)
Example #3
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_field_rename_inside_atomic_block(self): """ NotImplementedError is raised when a model field rename is attempted inside an atomic block. """ new_field = CharField(max_length=255, unique=True) new_field.set_attributes_from_name('renamed') msg = ( "Renaming the 'backends_author'.'name' column while in a " "transaction is not supported on SQLite because it would break " "referential integrity. Try adding `atomic = False` to the " "Migration class." ) with self.assertRaisesMessage(NotSupportedError, msg): with connection.schema_editor(atomic=True) as editor: editor.alter_field(Author, Author._meta.get_field('name'), new_field)
Example #4
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 6 votes |
def test_field_rename_inside_atomic_block(self): """ NotImplementedError is raised when a model field rename is attempted inside an atomic block. """ new_field = CharField(max_length=255, unique=True) new_field.set_attributes_from_name('renamed') msg = ( "Renaming the 'backends_author'.'name' column while in a " "transaction is not supported on SQLite < 3.26 because it would " "break referential integrity. Try adding `atomic = False` to the " "Migration class." ) with self.assertRaisesMessage(NotSupportedError, msg): with connection.schema_editor(atomic=True) as editor: editor.alter_field(Author, Author._meta.get_field('name'), new_field)
Example #5
Source File: test_mocks.py From django-mock-queries with MIT License | 6 votes |
def test_model_mocker_does_not_interfere_with_non_mocked_models(self): original_objects = CarVariation.objects with ModelMocker(Manufacturer) as make_mocker: self.assertEqual(Manufacturer.objects, make_mocker.objects) with ModelMocker(Car, outer=False) as car_mocker: self.assertEqual(Car.objects, car_mocker.objects) self.assertEqual(CarVariation.objects, original_objects) with self.assertRaises(NotSupportedError): CarVariation.objects.create(color='blue') with self.assertRaises(NotSupportedError): CarVariation(color='blue').save() with self.assertRaises(NotSupportedError): CarVariation(id=1, color='blue').save() with self.assertRaises(NotSupportedError): CarVariation(pk=1).delete() with self.assertRaises(NotSupportedError): CarVariation.objects.all().delete()
Example #6
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_disable_constraint_checking_failure_disallowed(self): """ SQLite schema editor is not usable within an outer transaction if foreign key constraint checks are not disabled beforehand. """ msg = ( 'SQLite schema editor cannot be used while foreign key ' 'constraint checks are enabled. Make sure to disable them ' 'before entering a transaction.atomic() context because ' 'SQLite does not support disabling them in the middle of ' 'a multi-statement transaction.' ) with self.assertRaisesMessage(NotSupportedError, msg): with transaction.atomic(), connection.schema_editor(atomic=True): pass
Example #7
Source File: test_qs_combinators.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_unsupported_intersection_raises_db_error(self): qs1 = Number.objects.all() qs2 = Number.objects.all() msg = 'intersection is not supported on this database backend' with self.assertRaisesMessage(NotSupportedError, msg): list(qs1.intersection(qs2))
Example #8
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_aggregation(self): """ Raise NotImplementedError when aggregating on date/time fields (#19360). """ for aggregate in (Sum, Avg, Variance, StdDev): with self.assertRaises(NotSupportedError): Item.objects.all().aggregate(aggregate('time')) with self.assertRaises(NotSupportedError): Item.objects.all().aggregate(aggregate('date')) with self.assertRaises(NotSupportedError): Item.objects.all().aggregate(aggregate('last_modified')) with self.assertRaises(NotSupportedError): Item.objects.all().aggregate( **{'complex': aggregate('last_modified') + aggregate('last_modified')} )
Example #9
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_table_rename_inside_atomic_block(self): """ NotImplementedError is raised when a table rename is attempted inside an atomic block. """ msg = ( "Renaming the 'backends_author' table while in a transaction is " "not supported on SQLite because it would break referential " "integrity. Try adding `atomic = False` to the Migration class." ) with self.assertRaisesMessage(NotSupportedError, msg): with connection.schema_editor(atomic=True) as editor: editor.alter_db_table(Author, "backends_author", "renamed_table")
Example #10
Source File: test_utils.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_unsupported_callproc_kparams_raises_error(self): msg = 'Keyword parameters for callproc are not supported on this database backend.' with self.assertRaisesMessage(NotSupportedError, msg): with connection.cursor() as cursor: cursor.callproc('test_procedure', [], {'P_I': 1})
Example #11
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_aggregation(self): """ Raise NotImplementedError when aggregating on date/time fields (#19360). """ for aggregate in (Sum, Avg, Variance, StdDev): with self.assertRaises(NotSupportedError): Item.objects.all().aggregate(aggregate('time')) with self.assertRaises(NotSupportedError): Item.objects.all().aggregate(aggregate('date')) with self.assertRaises(NotSupportedError): Item.objects.all().aggregate(aggregate('last_modified')) with self.assertRaises(NotSupportedError): Item.objects.all().aggregate( **{'complex': aggregate('last_modified') + aggregate('last_modified')} )
Example #12
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_distinct_aggregation(self): class DistinctAggregate(Aggregate): allow_distinct = True aggregate = DistinctAggregate('first', 'second', distinct=True) msg = ( "SQLite doesn't support DISTINCT on aggregate functions accepting " "multiple arguments." ) with self.assertRaisesMessage(NotSupportedError, msg): connection.ops.check_expression_support(aggregate)
Example #13
Source File: base.py From django-redshift-backend with Apache License 2.0 | 5 votes |
def _create_index_sql(self, model, fields, suffix="", sql=None): raise NotSupportedError("Redshift doesn't support INDEX")
Example #14
Source File: tests.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_table_rename_inside_atomic_block(self): """ NotImplementedError is raised when a table rename is attempted inside an atomic block. """ msg = ( "Renaming the 'backends_author' table while in a transaction is " "not supported on SQLite < 3.26 because it would break referential " "integrity. Try adding `atomic = False` to the Migration class." ) with self.assertRaisesMessage(NotSupportedError, msg): with connection.schema_editor(atomic=True) as editor: editor.alter_db_table(Author, "backends_author", "renamed_table")
Example #15
Source File: test_indexes.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_gin_parameters_exception(self): index_name = 'gin_options_exception' index = GinIndex(fields=['field'], name=index_name, gin_pending_list_limit=64) msg = 'GIN option gin_pending_list_limit requires PostgreSQL 9.5+.' with self.assertRaisesMessage(NotSupportedError, msg): with connection.schema_editor() as editor: editor.add_index(IntegerArrayModel, index) self.assertNotIn(index_name, self.get_constraints(IntegerArrayModel._meta.db_table))
Example #16
Source File: test_indexes.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_brin_index_not_supported(self): index_name = 'brin_index_exception' index = BrinIndex(fields=['field'], name=index_name) with self.assertRaisesMessage(NotSupportedError, 'BRIN indexes require PostgreSQL 9.5+.'): with mock.patch('django.db.backends.postgresql.features.DatabaseFeatures.has_brin_index_support', False): with connection.schema_editor() as editor: editor.add_index(CharFieldModel, index) self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
Example #17
Source File: test_indexes.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def test_brin_autosummarize_not_supported(self): index_name = 'brin_options_exception' index = BrinIndex(fields=['field'], name=index_name, autosummarize=True) with self.assertRaisesMessage(NotSupportedError, 'BRIN option autosummarize requires PostgreSQL 10+.'): with mock.patch('django.db.backends.postgresql.features.DatabaseFeatures.has_brin_autosummarize', False): with connection.schema_editor() as editor: editor.add_index(CharFieldModel, index) self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
Example #18
Source File: pgrefreshmv.py From django-postgres-extra with MIT License | 5 votes |
def handle(self, *app_labels, **options): app_label = options.get("app_label") model_name = options.get("model_name") concurrently = options.get("concurrently") model = apps.get_model(app_label, model_name) if not model: raise OperationalError(f"Cannot find a model named '{model_name}'") if not issubclass(model, PostgresMaterializedViewModel): raise NotSupportedError( f"Model {model.__name__} is not a `PostgresMaterializedViewModel`" ) model.refresh(concurrently=concurrently)
Example #19
Source File: test_redshift_backend.py From django-redshift-backend with Apache License 2.0 | 5 votes |
def test_distinct_with_fields(self): from testapp.models import TestModel query = TestModel.objects.distinct('text').query compiler = query.get_compiler(using='default') with self.assertRaises(NotSupportedError): compiler.as_sql()
Example #20
Source File: base.py From django-redshift-backend with Apache License 2.0 | 5 votes |
def distinct_sql(self, fields, *args): if fields: # https://github.com/jazzband/django-redshift-backend/issues/14 # Redshift doesn't support DISTINCT ON raise NotSupportedError('DISTINCT ON fields is not supported ' 'by this database backend') return super(DatabaseOperations, self).distinct_sql(fields, *args)
Example #21
Source File: base.py From django-redshift-backend with Apache License 2.0 | 5 votes |
def for_update_sql(self, nowait=False): raise NotSupportedError( 'SELECT FOR UPDATE is not implemented for this database backend')
Example #22
Source File: operations.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def check_expression_support(self, expression): bad_fields = (fields.DateField, fields.DateTimeField, fields.TimeField) bad_aggregates = (aggregates.Sum, aggregates.Avg, aggregates.Variance, aggregates.StdDev) if isinstance(expression, bad_aggregates): for expr in expression.get_source_expressions(): try: output_field = expr.output_field except FieldError: # Not every subexpression has an output_field which is fine # to ignore. pass else: if isinstance(output_field, bad_fields): raise utils.NotSupportedError( 'You cannot use Sum, Avg, StdDev, and Variance ' 'aggregations on date/time fields in sqlite3 ' 'since date/time is saved as text.' )
Example #23
Source File: schema.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def alter_field(self, model, old_field, new_field, strict=False): old_field_name = old_field.name table_name = model._meta.db_table _, old_column_name = old_field.get_attname_column() if (new_field.name != old_field_name and self._is_referenced_by_fk_constraint(table_name, old_column_name, ignore_self=True)): if self.connection.in_atomic_block: raise NotSupportedError(( 'Renaming the %r.%r column while in a transaction is not ' 'supported on SQLite because it would break referential ' 'integrity. Try adding `atomic = False` to the Migration class.' ) % (model._meta.db_table, old_field_name)) with atomic(self.connection.alias): super().alter_field(model, old_field, new_field, strict=strict) # Follow SQLite's documented procedure for performing changes # that don't affect the on-disk content. # https://sqlite.org/lang_altertable.html#otheralter with self.connection.cursor() as cursor: schema_version = cursor.execute('PRAGMA schema_version').fetchone()[0] cursor.execute('PRAGMA writable_schema = 1') references_template = ' REFERENCES "%s" ("%%s") ' % table_name new_column_name = new_field.get_attname_column()[1] search = references_template % old_column_name replacement = references_template % new_column_name cursor.execute('UPDATE sqlite_master SET sql = replace(sql, %s, %s)', (search, replacement)) cursor.execute('PRAGMA schema_version = %d' % (schema_version + 1)) cursor.execute('PRAGMA writable_schema = 0') # The integrity check will raise an exception and rollback # the transaction if the sqlite_master updates corrupt the # database. cursor.execute('PRAGMA integrity_check') # Perform a VACUUM to refresh the database representation from # the sqlite_master table. with self.connection.cursor() as cursor: cursor.execute('VACUUM') else: super().alter_field(model, old_field, new_field, strict=strict)
Example #24
Source File: schema.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def alter_db_table(self, model, old_db_table, new_db_table, disable_constraints=True): if disable_constraints and self._is_referenced_by_fk_constraint(old_db_table): if self.connection.in_atomic_block: raise NotSupportedError(( 'Renaming the %r table while in a transaction is not ' 'supported on SQLite because it would break referential ' 'integrity. Try adding `atomic = False` to the Migration class.' ) % old_db_table) self.connection.enable_constraint_checking() super().alter_db_table(model, old_db_table, new_db_table) self.connection.disable_constraint_checking() else: super().alter_db_table(model, old_db_table, new_db_table)
Example #25
Source File: schema.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def __enter__(self): # Some SQLite schema alterations need foreign key constraints to be # disabled. Enforce it here for the duration of the schema edition. if not self.connection.disable_constraint_checking(): raise NotSupportedError( 'SQLite schema editor cannot be used while foreign key ' 'constraint checks are enabled. Make sure to disable them ' 'before entering a transaction.atomic() context because ' 'SQLite3 does not support disabling them in the middle of ' 'a multi-statement transaction.' ) self.connection.cursor().execute('PRAGMA legacy_alter_table = ON') return super().__enter__()
Example #26
Source File: features.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def supports_stddev(self): """Confirm support for STDDEV and related stats functions.""" try: self.connection.ops.check_expression_support(StdDev(1)) except NotSupportedError: return False return True
Example #27
Source File: test_mocks.py From django-mock-queries with MIT License | 5 votes |
def test_not_mocked(self): m = Manufacturer() with self.assertRaisesRegexp( NotSupportedError, 'Mock database tried to execute SQL for Car model'): m.car_set.count()
Example #28
Source File: test_mocks.py From django-mock-queries with MIT License | 5 votes |
def test_not_mocked(self): car = Car(id=99) with self.assertRaises(NotSupportedError): car.sedan
Example #29
Source File: test_mocks.py From django-mock-queries with MIT License | 5 votes |
def test_exists_raises_error(self): """ Get a clear error if you forget to mock a database query. """ with self.assertRaisesRegexp( NotSupportedError, "Mock database tried to execute SQL for Car model."): Car.objects.exists()
Example #30
Source File: test_mocks.py From django-mock-queries with MIT License | 5 votes |
def test_mock_sql_raises_error(self): """ Get a clear error if you forget to mock a database query. """ with self.assertRaisesRegexp( NotSupportedError, "Mock database tried to execute SQL for Car model."): Car.objects.count()