django-cms icon indicating copy to clipboard operation
django-cms copied to clipboard

[BUG] Exception Type: InterfaceError Exception Value: cursor already closed

Open jpVm5jYYRE1VIKL opened this issue 2 years ago • 5 comments

Description

Quite often standard django cms drop exception InterfaceError Exception Value: cursor already closed during adding new plugins during edition of pages.

Steps to reproduce

Random but often

Expected behaviour

have to work normally

Actual behaviour

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 97, in inner
    return func(*args, **kwargs)

The above exception (cursor already closed) was the direct cause of the following exception:
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 204, in _get_response
    response = response.render()
  File "/usr/local/lib/python3.9/site-packages/django/template/response.py", line 105, in render
    self.content = self.rendered_content
  File "/usr/local/lib/python3.9/site-packages/django/template/response.py", line 83, in rendered_content
    return template.render(context, self._request)
  File "/usr/local/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/classytags/core.py", line 151, in render
    return self.render_tag(context, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/sekizai/templatetags/sekizai_tags.py", line 87, in render_tag
    rendered_contents = nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/classytags/core.py", line 151, in render
    return self.render_tag(context, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/cms/templatetags/cms_tags.py", line 443, in render_tag
    return toolbar.render_with_structure(context, nodelist)
  File "/usr/local/lib/python3.9/site-packages/cms/toolbar/toolbar.py", line 476, in render_with_structure
    rendered_contents = nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/classytags/core.py", line 151, in render
    return self.render_tag(context, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/cms/templatetags/cms_tags.py", line 305, in render_tag
    content = renderer.render_page_placeholder(
  File "/usr/local/lib/python3.9/site-packages/cms/plugin_rendering.py", line 327, in render_page_placeholder
    self._preload_placeholders_for_page(current_page)
  File "/usr/local/lib/python3.9/site-packages/cms/plugin_rendering.py", line 522, in _preload_placeholders_for_page
    assign_plugins(
  File "/usr/local/lib/python3.9/site-packages/cms/utils/plugins.py", line 74, in assign_plugins
    plugin_groups = dict((key, list(plugins)) for key, plugins in groupby(plugins, attrgetter('placeholder_id')))
  File "/usr/local/lib/python3.9/site-packages/cms/utils/plugins.py", line 74, in <genexpr>
    plugin_groups = dict((key, list(plugins)) for key, plugins in groupby(plugins, attrgetter('placeholder_id')))
  File "/usr/local/lib/python3.9/site-packages/cms/utils/plugins.py", line 284, in downcast_plugins
    for instance in plugin_qs.iterator():
  File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 360, in _iterator
    yield from self._iterable_class(self, chunked_fetch=use_chunked_fetch, chunk_size=chunk_size)
  File "/usr/local/lib/python3.9/site-packages/django/db/models/query.py", line 70, in __iter__
    for row in compiler.results_iter(results):
  File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1096, in apply_converters
    for row in map(list, rows):
  File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1606, in cursor_iter
    for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
  File "/usr/local/lib/python3.9/site-packages/django/db/models/sql/compiler.py", line 1606, in <lambda>
    for rows in iter((lambda: cursor.fetchmany(itersize)), sentinel):
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 97, in inner
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 97, in inner
    return func(*args, **kwargs)

Exception Type: InterfaceError at /en/products/equipment-thermal-cutting/
Exception Value: cursor already closed

Screenshots

Additional information (CMS/Python/Django versions)

used standard django cms quickstart repo.

Do you want to help fix this issue?

  • [ ] Yes, I want to help fix this issue and I will join #workgroup-pr-review on Slack to confirm with the community that a PR is welcome.
  • [x] No, I only want to report the issue.

jpVm5jYYRE1VIKL avatar May 22 '22 11:05 jpVm5jYYRE1VIKL

Same on postgre sql 14.4 django=3.2 django cms = 3.10.1

jpVm5jYYRE1VIKL avatar Jul 25 '22 18:07 jpVm5jYYRE1VIKL

@jpVm5jYYRE1VIKL This is likely a configuration issue with the web server.

Have a read of this; https://forum.djangoproject.com/t/db-connection-closed-by-uwsgi-in-the-middle-of-handling-a-request/9875/6

marksweb avatar Jul 25 '22 23:07 marksweb

@marksweb Most probabaly. But it happens with django-cms-quickstart standard project. So it does not have any specific settings.

jpVm5jYYRE1VIKL avatar Jul 26 '22 06:07 jpVm5jYYRE1VIKL

@jpVm5jYYRE1VIKL how are you running the quickstart project when you hit this error?

marksweb avatar Jul 26 '22 11:07 marksweb

@marksweb . Quite simple steps. Of course i added my own templates and menu. I also updated some libs in requirements.in (compiled it with pip-compile requirements.in >> requirements.txt) and also updated postgre separate image from 9.6-alpine to 14.4-alpine (because thought that may be issue binded with 9.6 pgre )

I build using Dockerfile image . after it assign tag to image and publish to registry after it i deploy image using compose using docker-compose.yml as an example (with adjustments about fresh built image , published port and pgre vestion).

this is my compose :

version: "3"

services:
  web:
    image: registry.mydomain.net/proj_web:1.1.6
    # map the internal port 80 to port 8000 on the host
    ports:
      - "28000:80"
    # map the host directory to app (which allows us to see and edit files inside the container)
    volumes:
      - "./data:/data:rw"
      - "./conf/settings.py:/app/backend/settings.py:ro"
      - "./logs:/logs:rw"
    # the default command to run whenever the container is launched
    command: uwsgi --http=0.0.0.0:80 --module=backend.wsgi --check-static=/data
    # command: python manage.py runserver 0.0.0.0:80
    # the URL 'postgres' or 'mysql' will point to the application's db service
    networks:
      - djangocmsnet

    env_file: .env-local

  database_default:
    # Select one of the following db configurations for the database
    image: postgres:14.4-alpine
    ports:
      - "5432:5432/tcp"  # allow your local dev env to connect to the db
    environment:
      POSTGRES_DB: "db"
      POSTGRES_PASSWORD: "password"
      POSTGRES_HOST_AUTH_METHOD: "trust"
      SERVICE_MANAGER: "fsm-postgres"

    networks:
      - djangocmsnet

networks:
  djangocmsnet:

Dockerfile:

FROM python:3.9
WORKDIR /app
COPY . /app
RUN pip install -r requirements.txt
RUN python manage.py collectstatic --noinput
CMD uwsgi --http=0.0.0.0:80 --module=backend.wsgi

settings.py

from pathlib import Path
import os
import dj_database_url
from django_storage_url import dsn_configured_storage_class

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get('SECRET_KEY', '<a string of random characters>')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DEBUG') == "True"

ALLOWED_HOSTS = [os.environ.get('DOMAIN'),]
if DEBUG:
    ALLOWED_HOSTS = ["*",]

CSRF_TRUSTED_ORIGINS = [os.environ.get('CSRF_TRUSTED_ORIGINS'),]

# Redirect to HTTPS by default, unless explicitly disabled
SECURE_SSL_REDIRECT = os.environ.get('SECURE_SSL_REDIRECT') != "False"

X_FRAME_OPTIONS = 'SAMEORIGIN'


# Application definition

INSTALLED_APPS = [
    'backend',

    # optional, but used in most projects
    'djangocms_admin_style',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'whitenoise.runserver_nostatic',  # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'django.contrib.staticfiles',
    'django.contrib.sites',

    # key django CMS modules
    'cms',
    'menus',
    'treebeard',
    'sekizai',

    # Django Filer - optional, but used in most projects
    'filer',
    'easy_thumbnails',

    # the default CKEditor - optional, but used in most projects
    'djangocms_text_ckeditor',

    # some content plugins - optional, but used in most projects
    'djangocms_file',
    'djangocms_icon',
    #'djangocms_link',
    'djangocms_picture',
    'djangocms_style',
    'djangocms_googlemap',
    'djangocms_video',
    # 'django_jsonfield_backport',

    # optional django CMS Bootstrap 4 modules
    # 'djangocms_bootstrap4',
    # 'djangocms_bootstrap4.contrib.bootstrap4_alerts',
    # 'djangocms_bootstrap4.contrib.bootstrap4_badge',
    # 'djangocms_bootstrap4.contrib.bootstrap4_card',
    # 'djangocms_bootstrap4.contrib.bootstrap4_carousel',
    # 'djangocms_bootstrap4.contrib.bootstrap4_collapse',
    # 'djangocms_bootstrap4.contrib.bootstrap4_content',
    # 'djangocms_bootstrap4.contrib.bootstrap4_grid',
    # 'djangocms_bootstrap4.contrib.bootstrap4_jumbotron',
    # 'djangocms_bootstrap4.contrib.bootstrap4_link',
    # 'djangocms_bootstrap4.contrib.bootstrap4_listgroup',
    # 'djangocms_bootstrap4.contrib.bootstrap4_media',
    # 'djangocms_bootstrap4.contrib.bootstrap4_picture',
    # 'djangocms_bootstrap4.contrib.bootstrap4_tabs',
    # 'djangocms_bootstrap4.contrib.bootstrap4_utilities',

    # optional django CMS Bootstrap 4 modules
    'djangocms_frontend',
    'djangocms_frontend.contrib.accordion',
    'djangocms_frontend.contrib.alert',
    'djangocms_frontend.contrib.badge',
    'djangocms_frontend.contrib.card',
    'djangocms_frontend.contrib.carousel',
    'djangocms_frontend.contrib.collapse',
    'djangocms_frontend.contrib.content',
    'djangocms_frontend.contrib.frontend_forms',
    'djangocms_frontend.contrib.grid',
    'djangocms_frontend.contrib.image',
    'djangocms_frontend.contrib.jumbotron',
    'djangocms_frontend.contrib.link',
    'djangocms_frontend.contrib.listgroup',
    'djangocms_frontend.contrib.media',
    'djangocms_frontend.contrib.tabs',
    'djangocms_frontend.contrib.utilities',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.locale.LocaleMiddleware',

    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'cms.middleware.language.LanguageCookieMiddleware',
]

ROOT_URLCONF = 'backend.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
                'django.template.context_processors.csrf',
                'django.template.context_processors.tz',
                'django.template.context_processors.i18n',

                'cms.context_processors.cms_settings',
                'sekizai.context_processors.sekizai',

            ],
        },
    },
]

CMS_TEMPLATES = [
    # a minimal template to get started with
    # ('minimal.html', 'Minimal template'),
    # ('whitenoise-static-files-demo.html', 'Static File Demo'),

    # optional templates that extend base.html, to be used with Bootstrap 5
    #('mainpage.html', 'Bootstrap MainPage'),
    ('mainpage-bs5.html', 'Bootstrap 5 MainPage'),
]

WSGI_APPLICATION = 'backend.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

# Configure database using DATABASE_URL; fall back to sqlite in memory when no
# environment variable is available, e.g. during Docker build
DATABASE_URL = os.environ.get('DATABASE_URL', 'sqlite://:memory:')
DATABASES = {'default': dj_database_url.parse(DATABASE_URL)}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

if not DEBUG:
    AUTH_PASSWORD_VALIDATORS = [
        {
            'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
        },
        {
            'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
        },
    ]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en'

LANGUAGES = [
    ('en', 'English'),
    ('ru', 'Russian'),
    ('de', 'German'),
    ('nl', 'Dutch'),
    ('sv', 'Swedish'),
    ('fi', 'Finnish'),
]

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_collected')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

# Media files
# DEFAULT_FILE_STORAGE is configured using DEFAULT_STORAGE_DSN

# read the setting value from the environment variable
DEFAULT_STORAGE_DSN = os.environ.get('DEFAULT_STORAGE_DSN')

# dsn_configured_storage_class() requires the name of the setting
DefaultStorageClass = dsn_configured_storage_class('DEFAULT_STORAGE_DSN')

# Django's DEFAULT_FILE_STORAGE requires the class name
DEFAULT_FILE_STORAGE = 'backend.settings.DefaultStorageClass'

# only required for local file storage and serving, in development
MEDIA_URL = 'media/'
MEDIA_ROOT = os.path.join('/data/media/')


SITE_ID = 1

DJANGOCMS_GOOGLEMAP_API_KEY = os.environ.get('DJANGOCMS_GOOGLEMAP_API_KEY')

DJANGOCMS_VIDEO_TEMPLATES = [
    ('youtube', ('Youtube Bootsrap')),
]

LOGGING = {
   'version': 1,
   'disable_existing_loggers': False,
   'handlers': {
      'file': {
         'level': 'ERROR',
         'class': 'logging.FileHandler',
         'filename': '/logs/debug.log',
      },
   },
   'loggers': {
      'django': {
         'handlers': ['file'],
         'level': 'ERROR',
         'propagate': True,
      },
   },
}

USE_X_FORWARDED_HOST = True

jpVm5jYYRE1VIKL avatar Jul 26 '22 11:07 jpVm5jYYRE1VIKL

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 24 '22 12:10 stale[bot]

This will now be closed due to inactivity, but feel free to reopen it.

stale[bot] avatar Nov 21 '22 20:11 stale[bot]