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

Duplicated Tag unique constraint error when creating multiple Content with same Tag #176

Closed
alexander-schranz opened this issue Jan 8, 2021 · 0 comments · Fixed by #180
Labels
Bug Error or unexpected behavior of already existing functionality

Comments

@alexander-schranz
Copy link
Member

alexander-schranz commented Jan 8, 2021

When we are creating a Document 1 with a Tag A and create a Document 2 also with a Tag A and the Tag A did not exist the TagFactory currently will create for Document 1 and Document 2 a new Tag aslong as between no "flush" of the entityManager was called and will error in a UniqueConstraint.

This can be fixed by #175 or a low version of it by just cache newly created tags and check for newly tags in the TagFactory:

        foreach ($tagNames as $key => $tagName) {
            if (isset($excerptTags[$key])) {
                continue;
            }
            
+            $tag = $this->createdTags[$tag->getName()] ?? null;

+            if (!$tag) {
                /** @var TagInterface $tag */
                $tag = $this->tagRepository->createNew();
                $tag->setName($tagName);
   
                $this->entityManager->persist($tag);
+               $this->createdTags[$tag->getName()] = $tag;
+            }

            $excerptTags[$key] = $tag;
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Error or unexpected behavior of already existing functionality
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant