python类OperationalError()的实例源码

apps.py 文件源码 项目:morango 作者: learningequality 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def ready(self):
        from django.core.management import call_command
        from morango.models import InstanceIDModel
        from morango.certificates import ScopeDefinition
        from .signals import add_to_deleted_models  # noqa: F401

        # NOTE: Warning: https://docs.djangoproject.com/en/1.10/ref/applications/#django.apps.AppConfig.ready
        # its recommended not to execute queries in this method, but we are producing the same result after the first call, so its OK

        # call this on app load up to get most recent system config settings
        try:
            InstanceIDModel.get_or_create_current_instance()
            if not ScopeDefinition.objects.filter():
                call_command("loaddata", "scopedefinitions")
        # we catch this error in case the database has not been migrated, b/c we can't query it until its been created
        except (OperationalError, ProgrammingError):
            pass

        # add models to be synced by profile
        add_syncable_models()
schema.py 文件源码 项目:CodingDojo 作者: ComputerSocietyUNB 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them)." % sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:NarshaTech 作者: KimJangHyeon 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:Scrum 作者: prakharchoudhary 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
checks.py 文件源码 项目:python-dockerflow 作者: mozilla-services 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def check_database_connected(app_configs, **kwargs):
    """
    A Django check to see if connecting to the configured default
    database backend succeeds.
    """
    errors = []

    try:
        connection.ensure_connection()
    except OperationalError as e:
        msg = 'Could not connect to database: {!s}'.format(e)
        errors.append(checks.Error(msg, id=ERROR_CANNOT_CONNECT_DATABASE))
    except ImproperlyConfigured as e:
        msg = 'Datbase misconfigured: "{!s}"'.format(e)
        errors.append(checks.Error(msg, id=ERROR_MISCONFIGURED_DATABASE))
    else:
        if not connection.is_usable():
            errors.append(checks.Error('Database connection is not usable',
                                       id=ERROR_UNUSABLE_DATABASE))

    return errors
__init__.py 文件源码 项目:pretalx 作者: pretalx 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def ready(self):
        from pretalx.event.models import Event
        from pretalx.common.tasks import regenerate_css
        from django.db import connection, utils

        if Event._meta.db_table not in connection.introspection.table_names():
            # commands like `compilemessages` execute ready(), but do not
            # require a database to be present. Bail out early, if the Event
            # table has not been created yet.
            return

        try:
            for event in Event.objects.all():
                regenerate_css.apply_async(args=(event.pk,))
        except (utils.OperationalError, utils.ProgrammingError):
            pass
schema.py 文件源码 项目:Gypsy 作者: benticarlos 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:DjangoBlog 作者: 0daybug 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them)." % sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
has_missing_migrations.py 文件源码 项目:django-react-boilerplate 作者: vintasoftware 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def handle(self, *args, **options):
        changed = set()

        self.stdout.write("Checking...")
        for db in settings.DATABASES.keys():
            try:
                executor = MigrationExecutor(connections[db])
            except OperationalError:
                sys.exit("Unable to check migrations: cannot connect to database\n")

            autodetector = MigrationAutodetector(
                executor.loader.project_state(),
                ProjectState.from_apps(apps),
            )
            changed.update(autodetector.changes(graph=executor.loader.graph).keys())

        changed -= set(options['ignore'])

        if changed:
            sys.exit(
                "Apps with model changes but no corresponding migration file: %(changed)s\n" % {
                    'changed': list(changed)
                })
        else:
            sys.stdout.write("All migration files present\n")
schema.py 文件源码 项目:wanblog 作者: wanzifa 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them)." % sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:wanblog 作者: wanzifa 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def create_spatial_indexes(self):
        for sql in self.geometry_sql:
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Cannot create SPATIAL INDEX %s. Only MyISAM and (as of "
                    "MySQL 5.7.5) InnoDB support them." % sql
                )
        self.geometry_sql = []
schema.py 文件源码 项目:tabmaster 作者: NicolasMinghetti 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them)." % sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:trydjango18 作者: lucifer-yqh 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them)." % sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:trydjango18 作者: wei0104 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them)." % sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:ims 作者: ims-team 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:lifesoundtrack 作者: MTG 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:django-open-lecture 作者: DmLitov4 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
utils.py 文件源码 项目:ddnet-django 作者: ddnet 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def reconnect_db(logfunc, default=None, retry_seconds=None):
    '''
    Catch Operational errors from the database and try to reconnect.
    '''
    def _decorator(func):
        def _wrapper(*args, **kwargs):
            while True:
                try:
                    return func(*args, **kwargs)
                except OperationalError as e:
                    logfunc(e)
                    close_old_connections()
                    if retry_seconds is None:
                        return default
                    else:
                        time.sleep(retry_seconds)
        _wrapper.__doc__ = func.__doc__
        return _wrapper
    return _decorator
schema.py 文件源码 项目:travlr 作者: gauravkulkarni96 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
models.py 文件源码 项目:trunk-player 作者: ScanOC 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def create_profile(sender, **kwargs):
    user = kwargs["instance"]
    if kwargs["created"]:
        default_plan = Plan.objects.get(pk=Plan.DEFAULT_PK)
        up = Profile(user=user, plan=default_plan)
        up.save()
        try:
            for tg in TalkGroupAccess.objects.filter(default_group=True):
                up.talkgroup_access.add(tg)
        except OperationalError:
            pass
        try:
            new_user_email = SiteOption.objects.get(name='SEND_ADMIN_EMAIL_ON_NEW_USER')
            if new_user_email.value_boolean_or_string() == True:
                send_mail(
                      'New {} User {}'.format(settings.SITE_TITLE, user.username),
                      'New User {} {} Username {} Email {} just registered'.format(user.first_name, user.last_name, user.username, user.email),
                      settings.SERVER_EMAIL,
                      [ mail for name, mail in settings.ADMINS],
                      fail_silently=False,
                     )
        except (SiteOption.DoesNotExist, OperationalError):
            pass
schema.py 文件源码 项目:logo-gen 作者: jellene4eva 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them)." % sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:gmail_scanner 作者: brandonhub 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them)." % sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them)." % sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
db.py 文件源码 项目:nav 作者: UNINETT 项目源码 文件源码 阅读 51 收藏 0 点赞 0 评论 0
def reset_connection_on_interface_error(func):
    """Decorates function to reset the current thread's Django database
    connection on exceptions that appear to come from connection resets.

    """
    def _reset(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except (InterfaceError, OperationalError,
                DjangoInterfaceError, DjangoOperationalError) as error:
            thread = threading.current_thread()
            _logger.warning("it appears this thread's database connection was "
                            "dropped, resetting it now - you may see further "
                            "errors about this until the situation is fully "
                            "resolved for all threads "
                            "(this thread is '%s', error was '%s')",
                            thread.name, error)
            django.db.connection.connection = None
            raise ResetDBConnectionError("The database connection was reset",
                                         error)

    return wraps(func)(_reset)
views.py 文件源码 项目:youtube-downloader-messenger-bot 作者: rrichajalota 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def generate_response(msg):
    """
    indices_list = []
    try:
        indices_list = QueryResults.objects.get(keyname = sno)
    except OperationalError:
        pass
    """

    if 'search' in msg:
        q = ''.join([ix for ix in msg.split('search', 1)[1]])
        #result = get_data(q)  #display the data resulting from a query search 
        return get_data(q)

    elif int(msg) in range(1,100): #fetch the link of that video
        link = get_video(int(msg))
        return link
    else:
        return "Use search 'search-term' to look for the video you want"
    #return msg
wait_for_database.py 文件源码 项目:django-gitlab-boilerplate 作者: motius 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def handle(self, *args, **options):
        try:
            connection = connections[options['database']]
        except ConnectionDoesNotExist:
            raise CommandError('Database "%s" does not exist in settings' % options['database'])

        for i in range(0, options['retries']):
            try:
                connection.cursor()
            except OperationalError:
                i += 1
                self.stdout.write('{} / {}: Waiting for database...'.format(i, options['retries']))
                sleep(options['sleep_time'])
            else:
                self.stdout.write(self.style.SUCCESS('Successfully connected to database'))
                return

        raise CommandError('Number of retries reached, exiting')
schema.py 文件源码 项目:CSCE482-WordcloudPlus 作者: ggaytan00 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)
schema.py 文件源码 项目:producthunt 作者: davidgengler 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def remove_field(self, model, field):
        if isinstance(field, GeometryField) and field.spatial_index:
            qn = self.connection.ops.quote_name
            sql = self.sql_drop_spatial_index % {
                'index': qn(self._create_spatial_index_name(model, field)),
                'table': qn(model._meta.db_table),
            }
            try:
                self.execute(sql)
            except OperationalError:
                logger.error(
                    "Couldn't remove spatial index: %s (may be expected "
                    "if your storage engine doesn't support them).", sql
                )

        super(MySQLGISSchemaEditor, self).remove_field(model, field)


问题


面经


文章

微信
公众号

扫码关注公众号