Skip to content

OBPIH-7414 fix duplicate tags and categories being created during pro…#5404

Merged
awalkowiak merged 2 commits intodevelopfrom
bug/OBPIH-7414-dupe-tags-cats-prod-import
Jul 25, 2025
Merged

OBPIH-7414 fix duplicate tags and categories being created during pro…#5404
awalkowiak merged 2 commits intodevelopfrom
bug/OBPIH-7414-dupe-tags-cats-prod-import

Conversation

@ewaterman
Copy link
Member

…duct import

✨ Description of Change

Link to GitHub issue or Jira ticket: https://pihemr.atlassian.net/browse/OBPIH-7414

Description: Two issues:

  • We were trying to fetch newly created tags/categories from the database before the cache was flushed, so even when one row created a category, when the next row fetches the same category, it isn't found, resulting in a duplicate being created
  • We weren't stripping whitespace so an import value of tags: "x, y" would result in tags "x" and " y" (note the space). So even if we already have a tag "y", "y" != " y", so we'd still create a new one

I refactored the code to first gather a list of all tags and categories being imported, then get or create them all in a batch, then use that result (without fetching from the db again) to populate the tags and categories in the product.


📷 Screenshots & Recordings (optional)

Here's a video showcasing the bug: https://www.loom.com/share/1a600be8b48e423eba8ba871bdff2b44

@ewaterman ewaterman self-assigned this Jul 23, 2025
@github-actions github-actions bot added type: bug Addresses unintended behaviours of the app domain: backend Changes or discussions relating to the backend server labels Jul 23, 2025
}

tag = new Tag(tag: tagName)
if (!tag.save()) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that after this refactor, we don't need to flush the cache when saving tags anymore since we're directly returning and using them (whereas before we'd try to fetch from the db later and so we had to ensure the db session was flushed).

@awalkowiak awalkowiak merged commit 318a6ca into develop Jul 25, 2025
6 checks passed
@awalkowiak awalkowiak deleted the bug/OBPIH-7414-dupe-tags-cats-prod-import branch July 25, 2025 08:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

domain: backend Changes or discussions relating to the backend server type: bug Addresses unintended behaviours of the app

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants