New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNIQUE constraint failed: documents_tag.name #384

Closed
kiliankoe opened this Issue Jul 21, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@kiliankoe

kiliankoe commented Jul 21, 2018

Hi 馃憢

I'm currently in the process of migrating a large amount of old scans to a new paperless instance. My current process was labeling documents according to the guesswork docs and adding them to the consume directory. All of the sudden though the consumer started crashing 馃槙

documents.models.DoesNotExist: Tag matching query does not exist.

Unfortunately I have no idea what is causing these errors. The tag SHK definitely exists, but even if it didn't, I thought that paperless would just go ahead and create it like it seems to be doing with correspondents.

Any help would be much appreciated, thanks! 馃槉

consumer_1  | Consuming /consume/TU Dresden - Lehrevaluation SoSe 2016 - SHK.pdf
consumer_1  | Skipping OCR, using Text from PDF
consumer_1  | Detected document date 2016-07-12T00:00:00+00:00 based on string 12.07.2016
consumer_1  | Traceback (most recent call last):
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 464, in get_or_create
consumer_1  |     return self.get(**lookup), False
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 380, in get
consumer_1  |     self.model._meta.object_name
consumer_1  | documents.models.DoesNotExist: Tag matching query does not exist.
consumer_1  |
consumer_1  | During handling of the above exception, another exception occurred:
consumer_1  |
consumer_1  | Traceback (most recent call last):
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
consumer_1  |     return self.cursor.execute(sql, params)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
consumer_1  |     return Database.Cursor.execute(self, query, params)
consumer_1  | sqlite3.IntegrityError: UNIQUE constraint failed: documents_tag.name
consumer_1  |
consumer_1  | The above exception was the direct cause of the following exception:
consumer_1  |
consumer_1  | Traceback (most recent call last):
consumer_1  |   File "/usr/src/paperless/src/manage.py", line 11, in <module>
consumer_1  |     execute_from_command_line(sys.argv)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
consumer_1  |     utility.execute()
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/core/management/__init__.py", line 356, in execute
consumer_1  |     self.fetch_command(subcommand).run_from_argv(self.argv)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/core/management/base.py", line 283, in run_from_argv
consumer_1  |     self.execute(*args, **cmd_options)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
consumer_1  |     output = self.handle(*args, **options)
consumer_1  |   File "/usr/src/paperless/src/documents/management/commands/document_consumer.py", line 98, in handle
consumer_1  |     self.loop_inotify(mail_delta)
consumer_1  |   File "/usr/src/paperless/src/documents/management/commands/document_consumer.py", line 131, in loop_inotify
consumer_1  |     self.loop_step(mail_delta)
consumer_1  |   File "/usr/src/paperless/src/documents/management/commands/document_consumer.py", line 123, in loop_step
consumer_1  |     self.file_consumer.consume_new_files()
consumer_1  |   File "/usr/src/paperless/src/documents/consumer.py", line 111, in consume_new_files
consumer_1  |     if not self.try_consume_file(file):
consumer_1  |   File "/usr/src/paperless/src/documents/consumer.py", line 154, in try_consume_file
consumer_1  |     date
consumer_1  |   File "/usr/src/paperless/src/documents/consumer.py", line 203, in _store
consumer_1  |     file_info = FileInfo.from_path(doc)
consumer_1  |   File "/usr/src/paperless/src/documents/models.py", line 483, in from_path
consumer_1  |     cls._mangle_property(properties, "tags")
consumer_1  |   File "/usr/src/paperless/src/documents/models.py", line 462, in _mangle_property
consumer_1  |     properties[name]
consumer_1  |   File "/usr/src/paperless/src/documents/models.py", line 446, in _get_tags
consumer_1  |     Tag.objects.get_or_create(slug=t, defaults={"name": t})[0])
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
consumer_1  |     return getattr(self.get_queryset(), name)(*args, **kwargs)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 466, in get_or_create
consumer_1  |     return self._create_object_from_params(lookup, params)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 506, in _create_object_from_params
consumer_1  |     six.reraise(*exc_info)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/utils/six.py", line 686, in reraise
consumer_1  |     raise value
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 498, in _create_object_from_params
consumer_1  |     obj = self.create(**params)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 394, in create
consumer_1  |     obj.save(force_insert=True, using=self.db)
consumer_1  |   File "/usr/src/paperless/src/documents/models.py", line 150, in save
consumer_1  |     models.Model.save(self, *args, **kwargs)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 808, in save
consumer_1  |     force_update=force_update, update_fields=update_fields)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 838, in save_base
consumer_1  |     updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 924, in _save_table
consumer_1  |     result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/base.py", line 963, in _do_insert
consumer_1  |     using=using, raw=raw)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/manager.py", line 85, in manager_method
consumer_1  |     return getattr(self.get_queryset(), name)(*args, **kwargs)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/query.py", line 1076, in _insert
consumer_1  |     return query.get_compiler(using=using).execute_sql(return_id)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/models/sql/compiler.py", line 1112, in execute_sql
consumer_1  |     cursor.execute(sql, params)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py", line 79, in execute
consumer_1  |     return super(CursorDebugWrapper, self).execute(sql, params)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
consumer_1  |     return self.cursor.execute(sql, params)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/utils.py", line 94, in __exit__
consumer_1  |     six.reraise(dj_exc_type, dj_exc_value, traceback)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/utils/six.py", line 685, in reraise
consumer_1  |     raise value.with_traceback(tb)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/backends/utils.py", line 64, in execute
consumer_1  |     return self.cursor.execute(sql, params)
consumer_1  |   File "/usr/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute
consumer_1  |     return Database.Cursor.execute(self, query, params)
consumer_1  | django.db.utils.IntegrityError: UNIQUE constraint failed: documents_tag.name
@danielquinn

This comment has been minimized.

Owner

danielquinn commented Jul 21, 2018

I have a silly question, but on the off chance I'm right, it'll help narrow down the problem. Have you tried changing the file name to TU Dresden - Lehrevaluation SoSe 2016 - shk.pdf (note the lower case tag name)?

@danielquinn

This comment has been minimized.

Owner

danielquinn commented Jul 21, 2018

Also, are you using sqlite or postgres? If you don't know, you're probably using sqlite.

@kiliankoe

This comment has been minimized.

kiliankoe commented Jul 21, 2018

Specifying the tag in all-lowercase seems to work, thanks! And yeah, I'm using an sqlite db, didn't even know postgres was an option 馃檲 I should probably have another look at the docs 馃槄

@danielquinn

This comment has been minimized.

Owner

danielquinn commented Jul 21, 2018

I'm not sure if the Postgres option is defined in the docs, but if you're familiar with Django, is familiar enough that setting it up is easy.

Ok, so this problem is clearly case-related and is probably easy to fix. We just need to make the lookup case-insensitive. I'll have a look at this when I've got some time, but as I'm on holiday right now, I promise nothing ;-)

@kiliankoe

This comment has been minimized.

kiliankoe commented Jul 21, 2018

I was hoping to maybe get myself familiar enough with using paperless and hacking on it to finally have a chance to get into using django 馃槃

Thanks so much for looking into this though! This is definitely not a high-priority issue, I'm glad there's an easy workaround. Have a great holiday 馃槉

@danielquinn

This comment has been minimized.

Owner

danielquinn commented Jul 21, 2018

Well I'm around if you have questions about hacking on Paperless :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment