openlibhums / janeway

A web-based platform for publishing journals, preprints, conference proceedings, and books
https://janeway.systems/
GNU Affero General Public License v3.0
175 stars 65 forks source link

HTML homepage element causing errors #1111

Closed Beethro closed 5 years ago

Beethro commented 5 years ago

Describe the bug errors connected with html homepage element in backend and frontend

Janeway version current git master with, lxml requiring version 4.2.6 for python 3.7 compatibility

To Reproduce

Two ways to reproduce:

  1. Journal Issue Manager, try to configure the html homepage element
  2. Allow users to change languages, then actually switch the language in the frontend

Additional context traceback:

Request Method: GET Request URL: http://xxx:8000/

Django Version: 1.11.20 Python Version: 3.7.3 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', 'cms', 'core', 'copyediting', 'cron', 'events', 'identifiers', 'journal', 'metrics', 'comms', 'preprint', 'press', 'production', 'proofing', 'review', 'reports', 'security', 'submission', 'transform', 'utils', 'install', 'django_summernote', 'markdown_deux', 'hvad', 'raven.contrib.django.raven_compat', 'bootstrap4', 'rest_framework', 'foundationform', 'materialize', 'snowpenguin.django.recaptcha2', 'simplemathcaptcha', 'django.forms', 'plugins.back_content', 'core.homepage_elements.carousel', 'core.homepage_elements.preprints', 'core.homepage_elements.news', 'core.homepage_elements.about', 'core.homepage_elements.featured', 'core.homepage_elements.issue', 'core.homepage_elements.html', 'core.homepage_elements.journals'] Installed Middleware: ('raven.contrib.django.middleware.SentryMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'core.middleware.TimezoneMiddleware', 'core.middleware.SiteSettingsMiddleware', 'utils.template_override_middleware.ThemeEngineMiddleware', 'core.middleware.MaintenanceModeMiddleware', 'cron.middleware.CronMiddleware', 'core.middleware.CounterCookieMiddleware', 'django.middleware.locale.LocaleMiddleware', 'core.middleware.PressMiddleware', 'core.middleware.GlobalRequestMiddleware', 'django.middleware.gzip.GZipMiddleware')

Traceback:

File "/opt/janeway/src/utils/setting_handler.py" in _get_plugin_setting

  1. journal=journal

File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/django/db/models/query.py" in get

  1. self.model._meta.object_name

During handling of the above exception (PluginSettingValueTranslation matching query does not exist.), another exception occurred:

File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner

  1. response = get_response(request)

File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/handlers/base.py" in _legacy_get_response

  1. response = self._get_response(request)

File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response

  1. response = self.process_exception_by_middleware(e, request)

File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response

  1. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/opt/janeway/src/press/views.py" in index

  1. return journal_views.home(request)

File "/opt/janeway/src/security/decorators.py" in wrapper

  1. return func(request, *args, **kwargs)

File "/opt/janeway/src/journal/views.py" in home

  1. element_context = function(request, homepage_elements)

File "/opt/janeway/src/core/homepage_elements/html/hooks.py" in yield_homepage_element_context

  1. html_block_content = setting_handler.get_plugin_setting(plugin, 'html_block_content', request.journal).value

File "/opt/janeway/src/utils/setting_handler.py" in get_plugin_setting

  1. return _get_plugin_setting(plugin, setting, journal, lang, create, fallback)

File "/opt/janeway/src/utils/setting_handler.py" in _get_plugin_setting

  1. journal=journal

File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/django/db/models/query.py" in get

  1. self.model._meta.object_name

Exception Type: DoesNotExist at / Exception Value: PluginSettingValueTranslation matching query does not exist.

Beethro commented 5 years ago

I should add that the frontend error only happens for / for languages != en /issues etc. work fine

ajrbyers commented 5 years ago

@mauromsl do you reckon this is related to the HVAD fallback issue you've been looking at?

mauromsl commented 5 years ago

Hi @Beethro, I tried to replicate your error by adding an HTML block with language set to "en". When I switched the user language to "fr" the HTML block loaded fine, just with the "en" value. Are these the steps you've follow yourself?

I've also added a small patch to log further details when this exception is raised. if you pull the latest changes in master you should get the following output on your dev server console:

CRITICAL 2019-05-07 11:07:12,506 setting_handler P:89 T:139628799186688 Failed to load plugin setting for context:
plugin: [HTML] 1.0 - True,
setting_name: html_block_content,
journal: orbit: orbit.openlibhums.org,
fallback: ,
request language: en,
settings language: en,

Do you mind pulling the latest changes, open the home page and send us the logged details?

Beethro commented 5 years ago

Hi @mauromsl,

I've tried the bugfix-1111 branch (thanks !) with a new database and we have pros and cons

(1062, "Duplicate entry '1-42' for key 'core_settingvalue_journal_id_setting_id_e8913d4f_uniq'")

Request Method: POST Request URL: http://xxx:8000/manager/settings/journal/ Django Version: 1.11.20 Exception Type: IntegrityError Exception Value:

(1062, "Duplicate entry '1-42' for key 'core_settingvalue_journal_id_setting_id_e8913d4f_uniq'")

Exception Location: /opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/connections.py in query, line 277 Python Executable: /opt/.virtualenvs/janeway/bin/python3.7 Python Version: 3.7.3 Python Path:

['/opt/janeway/src', '/opt/.virtualenvs/janeway/lib64/python37.zip', '/opt/.virtualenvs/janeway/lib64/python3.7', '/opt/.virtualenvs/janeway/lib64/python3.7/lib-dynload', '/usr/lib64/python3.7', '/usr/lib/python3.7', '/opt/.virtualenvs/janeway/lib/python3.7/site-packages', '/opt/.virtualenvs/janeway/src/django-bootstrap4', '/opt/.virtualenvs/janeway/src/foundationform', '/opt/.virtualenvs/janeway/src/django-mailgun', '/opt/.virtualenvs/janeway/src/django-simple-math-captcha', '/opt/.virtualenvs/janeway/src/dynamicsites', '/opt/.virtualenvs/janeway/src/ebooklib', '/opt/.virtualenvs/janeway/src/django-materialize', '/opt/janeway/src/plugins']

ERROR 2019-05-07 20:10:59,645 exception P:18463 T:140327156852480 Internal Server Error: /manager/settings/journal/ Traceback (most recent call last): File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 101, in execute return self.cursor.execute(query, args) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/cursors.py", line 250, in execute self.errorhandler(self, exc, value) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler raise errorvalue File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/cursors.py", line 247, in execute res = self._query(query) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/cursors.py", line 411, in _query rowcount = self._do_query(q) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/cursors.py", line 374, in _do_query db.query(q) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/connections.py", line 277, in query _mysql.connection.query(self, query) _mysql_exceptions.IntegrityError: (1062, "Duplicate entry '1-42' for key 'core_settingvalue_journal_id_setting_id_e8913d4f_uniq'")

mauromsl commented 5 years ago

Hi @Beethro, The latest changes in 1111-Bugfix should solve this issue.

Beethro commented 5 years ago

Hi @mauromsl

Close :) The first time around everything seems to work fine. e.g. I get english and german html content and descriptions. But when switching to german in the backend, and then submitting some changes in the journal settings I get the following

['/opt/janeway/src', '/opt/.virtualenvs/janeway/lib64/python37.zip', '/opt/.virtualenvs/janeway/lib64/python3.7', '/opt/.virtualenvs/janeway/lib64/python3.7/lib-dynload', '/usr/lib64/python3.7', '/usr/lib/python3.7', '/opt/.virtualenvs/janeway/lib/python3.7/site-packages', '/opt/.virtualenvs/janeway/src/django-bootstrap4', '/opt/.virtualenvs/janeway/src/foundationform', '/opt/.virtualenvs/janeway/src/django-mailgun', '/opt/.virtualenvs/janeway/src/django-simple-math-captcha', '/opt/.virtualenvs/janeway/src/dynamicsites', '/opt/.virtualenvs/janeway/src/ebooklib', '/opt/.virtualenvs/janeway/src/django-materialize', '/opt/janeway/src/plugins']

ERROR 2019-05-09 15:15:24,817 exception P:1406 T:140158473074432 Internal Server Error: /manager/settings/journal/ Traceback (most recent call last): File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 101, in execute return self.cursor.execute(query, args) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/cursors.py", line 250, in execute self.errorhandler(self, exc, value) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/connections.py", line 50, in defaulterrorhandler raise errorvalue File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/cursors.py", line 247, in execute res = self._query(query) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/cursors.py", line 411, in _query rowcount = self._do_query(q) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/cursors.py", line 374, in _do_query db.query(q) File "/opt/.virtualenvs/janeway/lib/python3.7/site-packages/MySQLdb/connections.py", line 277, in query _mysql.connection.query(self, query) _mysql_exceptions.IntegrityError: (1062, "Duplicate entry 'de-42' for key 'core_settingvalue_transl_language_code_master_id_0a7a4234_uniq'")

mauromsl commented 5 years ago

When you say you've changed the language in the backend, you mean changed settings.LANGUAGE_CODE from "en" to "de"?

Beethro commented 5 years ago

Should have said switching language in the management interface, i.e xxx/manager. The error occurs only the 2nd time around.

mauromsl commented 5 years ago

Ah you are right. That should be sorted as well now.

Beethro commented 5 years ago

Sorted !