当前位置: 首页>>代码示例>>Python>>正文


Python utils.NotSupportedError方法代码示例

本文整理汇总了Python中django.db.utils.NotSupportedError方法的典型用法代码示例。如果您正苦于以下问题:Python utils.NotSupportedError方法的具体用法?Python utils.NotSupportedError怎么用?Python utils.NotSupportedError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.utils的用法示例。


在下文中一共展示了utils.NotSupportedError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: callproc

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:19,代码来源:utils.py

示例2: test_model_mocker_does_not_interfere_with_non_mocked_models

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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() 
开发者ID:stphivos,项目名称:django-mock-queries,代码行数:26,代码来源:test_mocks.py

示例3: check_expression_support

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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.'
                        ) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:20,代码来源:operations.py

示例4: test_field_rename_inside_atomic_block

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:tests.py

示例5: test_field_rename_inside_atomic_block

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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) 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:tests.py

示例6: alter_db_table

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:15,代码来源:schema.py

示例7: alter_field

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
def alter_field(self, model, old_field, new_field, strict=False):
        old_field_name = old_field.name
        if (new_field.name != old_field_name and
                any(r.field_name == old_field.name for r in model._meta.related_objects)):
            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')
                    table_name = model._meta.db_table
                    references_template = ' REFERENCES "%s" ("%%s") ' % table_name
                    old_column_name = old_field.get_attname_column()[1]
                    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) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:39,代码来源:schema.py

示例8: mock_django_connection

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
def mock_django_connection(disabled_features=None):
    """ Overwrite the Django database configuration with a mocked version.

    This is a helper function that does the actual monkey patching.
    """
    db = connections.databases['default']
    db['PASSWORD'] = '****'
    db['USER'] = '**Database disabled for unit tests**'
    ConnectionHandler.__getitem__ = MagicMock(name='mock_connection')
    # noinspection PyUnresolvedReferences
    mock_connection = ConnectionHandler.__getitem__.return_value
    if disabled_features:
        for feature in disabled_features:
            setattr(mock_connection.features, feature, False)
    mock_ops = mock_connection.ops

    # noinspection PyUnusedLocal
    def compiler(queryset, connection, using, **kwargs):
        result = MagicMock(name='mock_connection.ops.compiler()')
        # noinspection PyProtectedMember
        result.execute_sql.side_effect = NotSupportedError(
            "Mock database tried to execute SQL for {} model.".format(
                queryset.model._meta.object_name))
        result.has_results.side_effect = result.execute_sql.side_effect
        return result

    mock_ops.compiler.return_value.side_effect = compiler
    mock_ops.integer_field_range.return_value = (-sys.maxsize - 1, sys.maxsize)
    mock_ops.max_name_length.return_value = sys.maxsize

    Model.refresh_from_db = Mock()  # Make this into a noop. 
开发者ID:stphivos,项目名称:django-mock-queries,代码行数:33,代码来源:mocks.py

示例9: test_mock_sql_raises_error

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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() 
开发者ID:stphivos,项目名称:django-mock-queries,代码行数:8,代码来源:test_mocks.py

示例10: test_exists_raises_error

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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() 
开发者ID:stphivos,项目名称:django-mock-queries,代码行数:8,代码来源:test_mocks.py

示例11: test_not_mocked

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
def test_not_mocked(self):
        car = Car(id=99)

        with self.assertRaises(NotSupportedError):
            car.sedan 
开发者ID:stphivos,项目名称:django-mock-queries,代码行数:7,代码来源:test_mocks.py

示例12: supports_stddev

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:9,代码来源:features.py

示例13: __enter__

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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__() 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:15,代码来源:schema.py

示例14: alter_db_table

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:15,代码来源:schema.py

示例15: alter_field

# 需要导入模块: from django.db import utils [as 别名]
# 或者: from django.db.utils import NotSupportedError [as 别名]
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) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:39,代码来源:schema.py


注:本文中的django.db.utils.NotSupportedError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。