Hey first of all thanks for all the great work putting this together eh, both the python ulid package itself and django_ulid.
I've run into an issue where when I run a query like:
'UPDATE "documents_document" SET numchild=numchild+1 WHERE path='0001' AND tree_root_pk='01EMF1XKJB3G1BXPKFC6MA7B04'
I get an error like: "can't adapt type 'ULID'""
I realized that this is because I need to str() the ULID id, otherwise I kept getting the ULID class object in my queries
But once I ensured the ULID is a string, I get the error:
Error: invalid input syntax for type uuid: "01EMF1XKJB3G1BXPKFC6MA7B04"
LINE 1: ...ild=numchild+1 WHERE path='0001' AND tree_root_pk='01EMF1XKJ...
From what I understand, this is simply the field failing postgres's uuid type checking (e.g. it's too short of a string). When I try everything the same, but with uuid-compatible string instead of ulid string, everything works because it passes the uuid typecheck
Now of course postgres doesn't have ulid type checking (tho apparently something similar is being proposed).
So I believe best bet is to forcefully cast the postgres field to ::text, but when I try that I get:
Error: operator does not exist: uuid = text
LINE 1: ...hild=numchild+1 WHERE path='0001' AND tree_root_pk='01EMF1XK...
So I'm not quite sure how to bypass postgres' uuid field checks on the django_ulid field. Is anyone else running into this issue?
Full Traceback:
Environment:
Request Method: POST
Request URL: http://127.0.0.1:8000/document/01EMF1XKJB3G1BXPKFC6MA7B04/
Django Version: 3.0.5
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.postgres.fields',
'django.contrib.humanize',
'users',
'documents.apps.DocumentsConfig',
'crispy_forms',
'treebeard',
'djstripe',
'froala_editor',
'debug_toolbar',
'django_extensions']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'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',
'users.middleware.CustomSubscriptionPaymentMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware']
Traceback (most recent call last):
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
The above exception (can't adapt type 'ULID') was the direct cause of the following exception:
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/project/documents/views.py", line 1098, in post
comment = comment_form.make_new_document_object()
File "/project/documents/forms.py", line 151, in make_new_document_object
new_object = self.target_object.add_child_plus_count(**data)
File "/project/documents/models.py", line 202, in add_child_plus_count
return self.add_child(**kwargs)
File "/project/documents/mp_tree.py", line 1031, in add_child
return MP_AddChildHandler(self, **kwargs).process()
File "/project/documents/mp_tree.py", line 373, in process
'sorted-sibling', **self.kwargs)
File "/project/documents/mp_tree.py", line 1043, in add_sibling
return MP_AddSiblingHandler(self, pos, **kwargs).process()
File "/project/documents/mp_tree.py", line 464, in process
self.run_sql_stmts()
File "/project/documents/mp_tree.py", line 149, in run_sql_stmts
cursor.execute(sql, vals)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/debug_toolbar/panels/sql/tracking.py", line 198, in execute
return self._record(self.cursor.execute, sql, params)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/debug_toolbar/panels/sql/tracking.py", line 133, in _record
return method(sql, params)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/db/backends/utils.py", line 100, in execute
return super().execute(sql, params)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/db/utils.py", line 90, in exit
raise dj_exc_value.with_traceback(traceback) from exc_value
File "/home/.virtualenvs/km_dev/lib/python3.7/site-packages/django/db/backends/utils.py", line 86, in _execute
return self.cursor.execute(sql, params)
Exception Type: ProgrammingError at /document/01EMF1XKJB3G1BXPKFC6MA7B04/
Exception Value: can't adapt type 'ULID'