﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29293	valid UUID is not a valid UUID	Jorge Alfaro	nobody	"When using UUIDField with postgresql sometimes the field initialization will fail, seems like postgresql sometimes returns some kind of UUID value that fails the 


{{{
isinstance(value, uuid.UUID)
}}}


validation and causes an exception, I don't really know how to reproduce, because for a time it happened to me almost every day (randomly), but it's been 7-8 months since the last time. I also want to clarify, once this problem ""starts"", it will fail every single time until you restart the server, after the restart everything works as it should (for a time aparently). I'm pretty sure it's not django's fault but it should be fairly easy to protect against this scenario. I think adding str() around value should fix this, it would look like this:


{{{
    def to_python(self, value):
        if value is not None and not isinstance(value, uuid.UUID):
            try:
                return uuid.UUID(str(value))
            except (AttributeError, ValueError):
                raise exceptions.ValidationError(
                    self.error_messages['invalid'],
                    code='invalid',
                    params={'value': value},
                )
        return value
}}}

Since django already is using the ""hex"" parameter for the UUID constructor and hex asumes a string, this makes sense to me

Link with aditional info:
[https://stackoverflow.com/questions/45990550/valid-uuid-is-not-a-valid-uuid]"	Cleanup/optimization	closed	Database layer (models, ORM)	1.11	Normal	invalid	UUIDField, postgresql, uuid		Unreviewed	0	0	0	0	0	0
