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

Unable to create unit (open-data slug duplicate) #2512

Closed
Battleman opened this issue Jun 23, 2023 · 2 comments
Closed

Unable to create unit (open-data slug duplicate) #2512

Battleman opened this issue Jun 23, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@Battleman
Copy link

Battleman commented Jun 23, 2023

Tandoor Version

1.5.1

Setup

Docker / Docker-Compose

Reverse Proxy

Traefik

Other

No response

Bug description

The new opendata slugs incorporated a constraint in the database, requiring unique (space_id, open_data_slug). If the space is not "enabled" with open-data, no unit have any open_data_slug.

For units specifically, creating a new entry doesn't add <null> but an empty string as the open_data_slug. This makes it impossible to add more units.

How to fix: Creating a new unit should use a NULL open_data_slug instead of an empty string.

Workaround: one needs to open the database, and manually change the open_data_slug from empty strings to NULL.

Relevant logs

Docker logs:

2023-06-23 17:31:20.397 UTC [3238] ERROR:  duplicate key value violates unique constraint "unit_unique_open_data_slug_per_space"

2023-06-23 17:31:20.397 UTC [3238] DETAIL:  Key (space_id, open_data_slug)=(1, ) already exists.

2023-06-23 17:31:20.397 UTC [3238] STATEMENT:  INSERT INTO "cookbook_unit" ("name", "plural_name", "description", "base_unit", "open_data_slug", "space_id") VALUES ('cup', 'cups', 'US Legal cup', NULL, '', 1) RETURNING "cookbook_unit"."id"

Database state

My table cookbook_unit after creating the entry "lb"; used \pset null '<null>' to show the null values:

 id  |   name   | description | space_id | plural_name | base_unit | open_data_slug 
-----+----------+-------------+----------+-------------+-----------+----------------
  91 | bâton    |             |        1 | bâtons      | <null>    | <null>
 113 | cm       | <null>      |        1 | <null>      | <null>    | <null>
 132 | lb       | Pounds      |        1 | lbs         | <null>    | 
  15 | kg       | <null>      |        1 | <null>      | <null>    | <null>
  10 | g        | <null>      |        1 | <null>      | <null>    | <null>
  50 | ml       | <null>      |        1 | <null>      | <null>    | <null>
@vabene1111
Copy link
Collaborator

that makes sense, the constraint would not allow multiple empty ones, will get this fixed

@vabene1111 vabene1111 added the bug Something isn't working label Jun 24, 2023
@vabene1111
Copy link
Collaborator

ok so fixed the uniqueness check by setting the field to none in the serializer. Not the nicest solutuion but i need to constraint to make bulk updating/inserting possible when importing from the open data repo (need to improve that as well, but works for now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants