Thursday, March 1, 2018

Re: UUIDs eventually choke as primary key

I added some debug support, and there are only two classes called UUID when this fails:
uuid   UUID: <module 'uuid' from '/usr/local/lib/python3.6/uuid.py'>
psycopg2.extensions   UUID: <module 'psycopg2.extensions' from '.../python3.6/site-packages/psycopg2/extensions.py'>

The psycopg extension is a converter, and it seems highly unlikely that it was put into place as the value, and I doubt it would report it's __str__ as the UUID string, so it does not appear to be a case of mistaken identity. Which makes the failure of "not instance" to catch the UUID after a while all the more weird...

I'm pretty baffled on this one. Am I really the only one running into this?

M

On Friday, February 23, 2018 at 1:17:34 PM UTC-8, M Mackey wrote:
Not to belabor the point, but this is the part that I find weird. This is down in the "During handling of the above exception ('UUID' object has no attribute 'replace'), another exception occurred" section.

/usr/local/venvs/attrack/lib/python3.6/site-packages/django/db/models/fields/__init__.py in to_python
        if value is not None and not isinstance(value, uuid.UUID): <<-------- 1) CHECKS FOR NOT UUID
            try:
                return uuid.UUID(value)  <<----- 2) Pretty sure first exception is in here
            except (AttributeError, ValueError):
                raise exceptions.ValidationError(
                    self.error_messages['invalid'],
                    code='invalid',
                    params={'value': value}, <<------  Traceback says new exception here
                )
        return value

Local vars
Variable Value
self <django.db.models.fields.UUIDField: id>
value UUID('338fa43f-3e07-4e83-8525-d195d2fc64d4')  <<-------- 3) REPORTS AS UUID

So, if 3) is right and 'value' is a UUID, 1) should keep us from getting to 2). But we get there.

On Friday, February 23, 2018 at 12:59:28 PM UTC-8, M Mackey wrote:
Adding details I seem to have left out. The id is defined like this:
id = models.UUIDField(primary_key=True, default=uuid.uuid1, editable=False)
and I'm running on PostgreSQL.
I'm pretty sure I never create a row without already having the key.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fd5fb988-78ae-40b7-ab5f-ca2d361b7d56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment