Thanks to visit codestin.com
Credit goes to github.com

Skip to content

UuidGenerator::class generates Symfony\Component\Uid\UuidV6 with default_uuid_version: 4 #44938

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

Closed
heuristicservices opened this issue Jan 6, 2022 · 2 comments

Comments

@heuristicservices
Copy link

heuristicservices commented Jan 6, 2022

Symfony version(s) affected

5.4.2

Description

Given a User entity (for demonstration purposes, not related to security) annotated with

 * @ORM\Id()
 * @ORM\GeneratedValue(strategy="CUSTOM")
 * @ORM\CustomIdGenerator(class=UuidGenerator::class)
 * @ORM\Column(type="uuid")
 */
private Uuid $id;

And the framework.yml configured with

uid:
    default_uuid_version: 4

Then doctrine will unexpectedly enter a UuidV6 UUID.

INSERT INTO users (id, email) VALUES (?, ?) 1={"Symfony\\Component\\Uid\\UuidV6":"1ec6f2d7-4149-60de-ac5b-174b92ac32c9"} 2="6fbb2834-21c2-4145-9d24-cc [...]"

The article https://symfony.com/blog/new-in-symfony-5-3-uid-improvements suggests that once configured, this should be UuidV4.

I think the documentation https://symfony.com/doc/current/components/uid.html also needs updating. as it says "There is no generator to assign UUIDs automatically as the value of your entity primary keys, but you can use the following" which is unexpected, considering there is the UuidGenerator::class, even though it seems to only generate V6 UUIDs.

Thank you.

How to reproduce

An example demonstrating the issue is here: https://github.com/heuristicservices/symfony-uuid

Run

docker-compose up

Migrate with

./bin/console doctrine:migrations:migrate

Navigating to

/user/add

will add some users.

Possible Solution

No response

Additional Context

No response

@heuristicservices heuristicservices changed the title UuidGenerator::class generates Symfony\\Component\\Uid\\UuidV6 with default_uuid_version: 4 UuidGenerator::class generates Symfony\Component\Uid\UuidV6 with default_uuid_version: 4 Jan 6, 2022
@fancyweb fancyweb self-assigned this Jan 7, 2022
@fancyweb
Copy link
Contributor

fancyweb commented Jan 7, 2022

Use @ORM\CustomIdGenerator("doctrine.uuid_generator") to reference the good service (see https://www.doctrine-project.org/projects/doctrine-bundle/en/2.4/custom-id-generators.html) and it works.

@fancyweb fancyweb closed this as completed Jan 7, 2022
@fancyweb
Copy link
Contributor

fancyweb commented Jan 7, 2022

Would you be up to fix the Symfony doc example btw?

PierreJoube added a commit to PierreJoube/symfony-docs that referenced this issue Feb 11, 2022
javiereguiluz added a commit to symfony/symfony-docs that referenced this issue Feb 17, 2022
This PR was merged into the 5.4 branch.

Discussion
----------

[Uid] Update uid.rst

Reference symfony/symfony#44938 (comment)

<!--

If your pull request fixes a BUG, use the oldest maintained branch that contains
the bug (see https://symfony.com/releases for the list of maintained branches).

If your pull request documents a NEW FEATURE, use the same Symfony branch where
the feature was introduced (and `6.x` for features of unreleased versions).

-->

Commits
-------

91872e4 Update uid.rst
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants