Skip to content

Primary Key Constraint missing on some models #7128

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
ewdurbin opened this issue Dec 19, 2019 · 2 comments
Closed

Primary Key Constraint missing on some models #7128

ewdurbin opened this issue Dec 19, 2019 · 2 comments

Comments

@ewdurbin
Copy link
Member

The following models/tables have a UUID id column but are missing a Unique Index and Primary Key Constraint on the column:

  • File/release_files
  • Dependency/release_dependencies
  • Role/roles

I'm not sure how we ended up in this state, but it seems something was missed in #4958 when migrating to surrogate keys.

ewdurbin added a commit that referenced this issue Dec 19, 2019
ewdurbin added a commit that referenced this issue Dec 19, 2019
@ewdurbin
Copy link
Member Author

At least for File/release_files it appears to just be a relic from when it was initially mapped into the ORM

@ewdurbin
Copy link
Member Author

Since SQLAlchemy believes these primary keys exist

>>> from sqlalchemy.inspection import inspect
>>> from warehouse.packaging.models import File
>>> inspect(File).primary_key
(Column('id', UUID(as_uuid=True), table=<release_files>, primary_key=True, nullable=False, server_default=DefaultClause(<sqlalchemy.sql.elements.TextClause object at 0x7fe5445588d0>, for_update=False)),)
>>> from warehouse.packaging.models import Dependency
>>> inspect(Dependency).primary_key
(Column('id', UUID(as_uuid=True), table=<release_dependencies>, primary_key=True, nullable=False, server_default=DefaultClause(<sqlalchemy.sql.elements.TextClause object at 0x7fe5445588d0>, for_update=False)),)
>>> from warehouse.packaging.models import Role
>>> inspect(Role).primary_key
(Column('id', UUID(as_uuid=True), table=<roles>, primary_key=True, nullable=False, server_default=DefaultClause(<sqlalchemy.sql.elements.TextClause object at 0x7fe5445588d0>, for_update=False)),)

but the underlying schema does not have them errors such as

sqlalchemy.exc.ProgrammingError: (psycopg2.errors.InvalidForeignKey) there is no unique constraint matching given keys for referenced table "release_files"

Arise when referencing them in relations.

ewdurbin added a commit that referenced this issue Dec 19, 2019
* add missing primary key constraints

addresses #7128

* lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant