Skip to content
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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UUIDPrimaryKeyMixin _always_ provides a UUID on create #485

Closed
garzola opened this issue Aug 6, 2021 · 4 comments
Closed

UUIDPrimaryKeyMixin _always_ provides a UUID on create #485

garzola opened this issue Aug 6, 2021 · 4 comments

Comments

@garzola
Copy link
Contributor

garzola commented Aug 6, 2021

When using the UUIDPrimaryKeyMixin, all works well when creating new entries. However, when creating a new entry that already has an id, the UUIDPrimaryKeyMixin will ignore the provided UUID and replace it with a new one. This is not the behavior expected -- if I provide an id on creation, I do not expect it to be replaced.

In the file scopes/UUIDPrimaryKeyScope.py file, the following is a quick fix:

    def set_uuid_create(self, builder):
        # if there is already a primary key, no need to set a new one
        if not builder._model.__primary_key__:
            uuid_version = getattr(builder._model, "__uuid_version__", 4)
            builder._creates.update(
                {builder._model.__primary_key__: self.generate_uuid(builder, uuid_version)}
            )

to replace:

    def set_uuid_create(self, builder):
        uuid_version = getattr(builder._model, "__uuid_version__", 4)
        builder._creates.update(
            {builder._model.__primary_key__: self.generate_uuid(builder, uuid_version)}
        )
@josephmancuso
Copy link
Member

@garzola Thanks for reporting this! Would you mind opening up a PR for this fix?

@garzola
Copy link
Contributor Author

garzola commented Aug 6, 2021

PR == Pull Request? Yes, I'm happy to do that. I won't be able to do this until later this evening.

@josephmancuso
Copy link
Member

Yup exactly. I won't be able to review this until tonight anyway so thats fine

@josephmancuso
Copy link
Member

Fixed in #486

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants