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

Continue looking for available names when an auto-generated constraint name is unavailable #1014

Closed
seancolsen opened this issue Jan 24, 2022 · 6 comments
Assignees
Labels
help wanted Community contributors can implement this ready Ready for implementation type: bug Something isn't working work: backend Related to Python, Django, and simple SQL
Milestone

Comments

@seancolsen
Copy link
Contributor

Summary

When the API receives a POST request at /tables/{table_id}/constraints/ without a name parameter, it will auto-generate a constraint name. If the name it auto-generates isn't available, it will give up, returning an error.

Reproduce

  1. Add a new empty table named foo_bar_key.

  2. Add a new table with imported data by pasting the following and setting the table name to foo.

    bar
    2
  3. Within the foo table, disallow duplicates for the bar column.

  4. Expect success.

  5. Observe an error:

    Unable to update "Allow Duplicates" of column "bar". Relation with the same name already exists.

Desired behavior

Instead of giving up right away, the backend should continue looking for available names by appending suffixes such as _1, _2, etc.

@seancolsen seancolsen added ready Ready for implementation type: bug Something isn't working work: backend Related to Python, Django, and simple SQL labels Jan 24, 2022
@seancolsen seancolsen changed the title Continue looking for available names when auto-generating constraint names Continue looking for available names when an auto-generated constraint name is unavailable Jan 24, 2022
@kgodey kgodey added the help wanted Community contributors can implement this label Mar 5, 2022
@A1O
Copy link
Contributor

A1O commented Apr 4, 2022

I'd like to work on this issue.

@kgodey kgodey added status: started and removed ready Ready for implementation labels Apr 5, 2022
@kgodey
Copy link
Contributor

kgodey commented Apr 5, 2022

Go ahead, @A1O!

@kgodey
Copy link
Contributor

kgodey commented May 6, 2022

@A1O are you still working on this?

@kgodey kgodey removed this from the [08.1] 2022-05 improvements milestone Jun 1, 2022
@kgodey kgodey unassigned A1O Jun 2, 2022
@kgodey kgodey added help wanted Community contributors can implement this ready Ready for implementation and removed help wanted Community contributors can implement this status: started labels Jun 2, 2022
@kgodey kgodey added this to the High Priority milestone Jun 2, 2022
@github-actions
Copy link

github-actions bot commented Feb 4, 2023

This issue has not been updated in 90 days and is being marked as stale.

@github-actions github-actions bot added the stale label Feb 4, 2023
@pavish pavish removed the stale label Mar 15, 2023
@purujit
Copy link

purujit commented Sep 26, 2023

@kgodey I believe this is no longer an issue - possibly due to the new version of Postgres. When I run the reproduction steps, it no longer fails and finds a unique name for the constraint. See below how it picked foo_bar_key1 for the repro steps mentioned in this bug and foo_baz_key when there was no conflict. If you agree, please assign it to me and resolve as fixed :)

mathesar=# 
SELECT
conname AS constraint_name,
conrelid::regclass AS referring_table, 
confrelid::regclass AS referenced_table
FROM pg_catalog.pg_constraint;
       constraint_name        |         referring_table          | referenced_table 
------------------------------+----------------------------------+------------------
 cardinal_number_domain_check | -                                | -
 yes_or_no_check              | -                                | -
 email_check                  | -                                | -
 uri_check                    | -                                | -
 top_level_domains_pkey       | mathesar_types.top_level_domains | -
 mathesar_json_array_check    | -                                | -
 mathesar_json_object_check   | -                                | -
 patents_pkey                 | sample.patents                   | -
 Table 1_pkey                 | sample.foo_bar_key               | -
 Table 2_pkey                 | sample.foo                       | -
 foo_bar_key1                 | sample.foo                       | -
 foo_baz_key                  | sample.foo                       | -
(12 rows)

@seancolsen
Copy link
Contributor Author

Thanks for looking into this, @purujit

I can confirm that I'm no longer able to reproduce this bug.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Community contributors can implement this ready Ready for implementation type: bug Something isn't working work: backend Related to Python, Django, and simple SQL
Projects
No open projects
Development

No branches or pull requests

5 participants