Friday, February 23, 2018

Re: UUIDs eventually choke as primary key

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/ea0820eb-8cf4-478e-ba4a-8535c420fce0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment