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

.add_foreign_keys() doesn't reject being called with a View #313

Closed
simonw opened this issue Aug 10, 2021 · 0 comments
Closed

.add_foreign_keys() doesn't reject being called with a View #313

simonw opened this issue Aug 10, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Aug 10, 2021

Spotted this bug using mypy while working on #311 / #312!

% mypy sqlite_utils
sqlite_utils/db.py:725: error: Item "View" of "Union[Table, View]" has no attribute "foreign_keys"
Found 1 error in 1 file (checked 5 source files)

Refers to this code:

# We will silently skip foreign keys that exist already
if not any(
fk
for fk in self[table].foreign_keys
if fk.column == column
and fk.other_table == other_table
and fk.other_column == other_column
):
foreign_keys_to_create.append(
(table, column, other_table, other_column)
)

It's a bug! We run some checks earlier but none of them ensure that it's a view:

if not self[table].exists():
raise AlterError("No such table: {}".format(table))
if column not in self[table].columns_dict:
raise AlterError("No such column: {} in {}".format(column, table))
if not self[other_table].exists():
raise AlterError("No such other_table: {}".format(other_table))
if (
other_column != "rowid"
and other_column not in self[other_table].columns_dict
):
raise AlterError(
"No such other_column: {} in {}".format(other_column, other_table)
)

@simonw simonw added the bug Something isn't working label Aug 10, 2021
simonw added a commit that referenced this issue Aug 10, 2021
@simonw simonw closed this as completed Aug 10, 2021
simonw added a commit that referenced this issue Aug 10, 2021
* Docstrings and type annotations for almost every method
* New /reference API documentation page using Sphink autodoc
* Custom Read The Docs config, to get autodoc working
* Fix for #313 (add_foreign_keys() doesn't reject being called with a View)
* Fixed #315 (.delete_where() returns [] when it should return self)
simonw added a commit that referenced this issue Aug 10, 2021
simonw added a commit that referenced this issue Aug 10, 2021
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

1 participant