openlibhums / janeway

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

Unique constraint failed when using alter_domains #558

Closed mdlincoln closed 5 years ago

mdlincoln commented 6 years ago

While loading data from two journals into a Janeway instance with URL_CONFIG = 'path', we wanted to run alter_domains to shift the domains of two journals. This succeeded with the first journal, but when trying to alter the domain of the second, it threw a unique constraint failure. While I'd expect this error for URL_CONFIG = 'domain', when using path we'd very much want the domain to be the same.

(I've only tested this problem when using an sqlite backend)

``` Altering sites record...Traceback (most recent call last): File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, inexecute return self.cursor.execute(sql, params) File "/usr/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line328, in execute return Database.Cursor.execute(self, query, params) sqlite3.IntegrityError: UNIQUE constraint failed: django_site.domain The above exception was the direct cause of the following exception: Traceback (most recent call last): File "manage.py", line 11, in execute_from_command_line(sys.argv) File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line364, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.6/site-packages/django/core/management/__init__.py", line356, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv self.execute(*args, **cmd_options) File "/usr/local/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute output = self.handle(*args, **options) File "/janeway/src/utils/management/commands/alter_domains.py", line 68, in handle site.save() File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 807, in save force_update=force_update, update_fields=update_fields) File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 837, in save_base updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 904, in _save_table forced_update) File "/usr/local/lib/python3.6/site-packages/django/db/models/base.py", line 954, in _do_update return filtered._update(values) > 0 File "/usr/local/lib/python3.6/site-packages/django/db/models/query.py", line 664, in _update return query.get_compiler(self.db).execute_sql(CURSOR) File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1199, in execute_sql cursor = super(SQLUpdateCompiler, self).execute_sql(result_type) File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 894, in execute_sql raise original_exception File "/usr/local/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 884, in execute_sql cursor.execute(sql, params) File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 80, inexecute return super(CursorDebugWrapper, self).execute(sql, params) File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, inexecute return self.cursor.execute(sql, params) File "/usr/local/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/usr/local/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise raise value.with_traceback(tb) File "/usr/local/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, inexecute return self.cursor.execute(sql, params) File "/usr/local/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line328, in execute return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: UNIQUE constraint failed: django_site.domain ```
ajrbyers commented 6 years ago

This is an interesting one. For Domain we want it to be unique... wondering if the best solution is for path based to assign the domains automatically...

mauromsl commented 6 years ago

The domain is part of the django built in django.contrib.sites.models.Site model. We could simply stop using the sites framework when the settings are configured with URL_CONFIG = "path", ignoring the journal domain.

This would mean that when you use path for URL_CONFIG, you can't have different domains for different journals, but it feels like that is the entire purpose of using domain for URL_CONFIG.