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 special mypy plugin/support for SQLAlchemy #6346

Closed
legoktm opened this issue Mar 16, 2022 · 1 comment · Fixed by #6351
Closed

Add special mypy plugin/support for SQLAlchemy #6346

legoktm opened this issue Mar 16, 2022 · 1 comment · Fixed by #6351
Assignees
Milestone

Comments

@legoktm
Copy link
Member

legoktm commented Mar 16, 2022

Description

I did not verify this, but I suspect that #6342 could've been avoided if mypy was able to understand that nullable=True maps to Optional[...] in Python types and complained about not checking for is not None first.

In the past I've used https://github.com/dropbox/sqlalchemy-stubs for this purpose. SQLAlchemy also has its own mypy plugin based off the Dropbox one, https://docs.sqlalchemy.org/en/14/orm/extensions/mypy.html, but I haven't personally used it.

We should investigate one or both of these and see if it improves what mypy can detect in terms of type issues.

@legoktm
Copy link
Member Author

legoktm commented Mar 18, 2022

This was actually attempted in #5589, but missed the step of adding the plugin to mypy, so it didn't have much of an impact :(

When I enabled it locally (and upgraded mypy), the main thing it caught is that Source.filesystem_id is technically nullable, even though in practice it never is. Still have some more to clean up before I push a PR.

legoktm added a commit that referenced this issue Mar 18, 2022
We already set this field all the time and in all places expect it to be
a string, not checking if its None first.

Discovered by the mypy work I'm doing in #6346.

Refs #6226.
legoktm added a commit that referenced this issue Mar 18, 2022
* Upgrade mypy to 0.941 and sqlalchemy-stubs to 0.4. Type stubs are no
  longer bundled with mypy, so we need to explicitly install various
  types-{name} packages.
* The main issue spotted by the SQLAlchemy plugin, that
  sources.filesystem_id is nullable, is being fixed in a separate PR:
  #6350.
* Use `--explicit-package-bases` when running mypy, so it treats the
  securedrop/admin directories as modules regardless of whether
  `__init__.py` files exist. This is needed so the two tests/
  directories don't conflict with each other.
* Add missing return types to all schema changes and the templates that
  generate them.
* In the `create_source_uuid_column` migration, drop the use of
  `quoted_name()`. For some reason mypy doesn't like it, but more
  importantly we don't need it in SQLite and we don't use it in any
  other schema change.
* Make SecureTemporaryFile.write()'s return type match its parent by
  returning the number of bytes that were written.

Fixes #6346.
@legoktm legoktm self-assigned this Mar 18, 2022
legoktm added a commit that referenced this issue Mar 21, 2022
We already set this field all the time and in all places expect it to be
a string, not checking if its None first.

Discovered by the mypy work I'm doing in #6346.

Refs #6226.
legoktm added a commit that referenced this issue Mar 21, 2022
* Upgrade mypy to 0.941 and sqlalchemy-stubs to 0.4. Type stubs are no
  longer bundled with mypy, so we need to explicitly install various
  types-{name} packages.
* The main issue spotted by the SQLAlchemy plugin, that
  sources.filesystem_id is nullable, is being fixed in a separate PR:
  #6350.
* Use `--explicit-package-bases` when running mypy, so it treats the
  securedrop/admin directories as modules regardless of whether
  `__init__.py` files exist. This is needed so the two tests/
  directories don't conflict with each other.
* Add missing return types to all schema changes and the templates that
  generate them.
* In the `create_source_uuid_column` migration, drop the use of
  `quoted_name()`. For some reason mypy doesn't like it, but more
  importantly we don't need it in SQLite and we don't use it in any
  other schema change.
* Make SecureTemporaryFile.write()'s return type match its parent by
  returning the number of bytes that were written.

Fixes #6346.
legoktm added a commit that referenced this issue Mar 22, 2022
* Upgrade mypy to 0.941 and sqlalchemy-stubs to 0.4. Type stubs are no
  longer bundled with mypy, so we need to explicitly install various
  types-{name} packages.
* The main issue spotted by the SQLAlchemy plugin, that
  sources.filesystem_id is nullable, is being fixed in a separate PR:
  #6350.
* Drop the explicit type comments now that mypy can infer them.
* Use `--explicit-package-bases` when running mypy, so it treats the
  securedrop/admin directories as modules regardless of whether
  `__init__.py` files exist. This is needed so the two tests/
  directories don't conflict with each other.
* Add missing return types to all schema changes and the templates that
  generate them.
* In the `create_source_uuid_column` migration, drop the use of
  `quoted_name()`. For some reason mypy doesn't like it, but more
  importantly we don't need it in SQLite and we don't use it in any
  other schema change.
* Make SecureTemporaryFile.write()'s return type match its parent by
  returning the number of bytes that were written.

Fixes #6346.
legoktm added a commit that referenced this issue Mar 23, 2022
* Upgrade mypy to 0.941 and sqlalchemy-stubs to 0.4. Type stubs are no
  longer bundled with mypy, so we need to explicitly install various
  types-{name} packages.
* The main issue spotted by the SQLAlchemy plugin, that
  sources.filesystem_id is nullable, is being fixed in a separate PR:
  #6350.
* Drop the explicit type comments now that mypy can infer them.
* Use `--explicit-package-bases` when running mypy, so it treats the
  securedrop/admin directories as modules regardless of whether
  `__init__.py` files exist. This is needed so the two tests/
  directories don't conflict with each other.
* Add missing return types to all schema changes and the templates that
  generate them.
* In the `create_source_uuid_column` migration, drop the use of
  `quoted_name()`. For some reason mypy doesn't like it, but more
  importantly we don't need it in SQLite and we don't use it in any
  other schema change.
* Make SecureTemporaryFile.write()'s return type match its parent by
  returning the number of bytes that were written.

Fixes #6346.
@legoktm legoktm added this to the 2.4.0 milestone Mar 30, 2022
legoktm added a commit that referenced this issue Mar 31, 2022
* Upgrade mypy to 0.942 and sqlalchemy-stubs to 0.4. Type stubs are no
  longer bundled with mypy, so we need to explicitly install various
  types-{name} packages.
* Since we need to install extra packages and need other dependencies
  like Flask, move mypy into test-requirements.txt and run it via the
  dev container.
* The main issue spotted by the SQLAlchemy plugin, that
  sources.filesystem_id is nullable, is being fixed in a separate PR:
  #6350.
* Drop the explicit type comments now that mypy can infer them.
* Use `--explicit-package-bases` when running mypy, so it treats the
  securedrop/admin directories as modules regardless of whether
  `__init__.py` files exist. This is needed so the two tests/
  directories don't conflict with each other.
* Add missing return types to all schema changes and the templates that
  generate them.
* In the `create_source_uuid_column` migration, drop the use of
  `quoted_name()`. For some reason mypy doesn't like it, but more
  importantly we don't need it in SQLite and we don't use it in any
  other schema change.
* Make SecureTemporaryFile.write()'s return type match its parent by
  returning the number of bytes that were written.

Fixes #6346.
Fixes #6358.
legoktm added a commit that referenced this issue Mar 31, 2022
* Upgrade mypy to 0.942 and sqlalchemy-stubs to 0.4. Type stubs are no
  longer bundled with mypy, so we need to explicitly install various
  types-{name} packages.
* Since we need to install extra packages and need other dependencies
  like Flask, move mypy into test-requirements.txt and run it via the
  dev container.
* The main issue spotted by the SQLAlchemy plugin, that
  sources.filesystem_id is nullable, is being fixed in a separate PR:
  #6350.
* Drop the explicit type comments now that mypy can infer them.
* Use `--explicit-package-bases` when running mypy, so it treats the
  securedrop/admin directories as modules regardless of whether
  `__init__.py` files exist. This is needed so the two tests/
  directories don't conflict with each other.
* Add missing return types to all schema changes and the templates that
  generate them.
* In the `create_source_uuid_column` migration, drop the use of
  `quoted_name()`. For some reason mypy doesn't like it, but more
  importantly we don't need it in SQLite and we don't use it in any
  other schema change.
* Make SecureTemporaryFile.write()'s return type match its parent by
  returning the number of bytes that were written.

Fixes #6346.
Fixes #6358.
legoktm added a commit that referenced this issue Mar 31, 2022
We already set this field all the time and in all places expect it to be
a string, not checking if its None first.

The database migration will delete any sources that have a NULL filesystem_id,
plus anything that references those sources.

Discovered by the mypy work I'm doing in #6346.

Refs #6226.
legoktm added a commit that referenced this issue Apr 1, 2022
We already set this field all the time and in all places expect it to be
a string, not checking if its None first.

The database migration will delete any sources that have a NULL filesystem_id,
plus anything that references those sources.

Discovered by the mypy work I'm doing in #6346.

Refs #6226.
legoktm added a commit that referenced this issue Apr 1, 2022
We already set this field all the time and in all places expect it to be
a string, not checking if its None first.

The database migration will delete any sources that have a NULL filesystem_id,
plus anything that references those sources.

Discovered by the mypy work I'm doing in #6346.

Refs #6226.
legoktm added a commit that referenced this issue Apr 1, 2022
We already set this field all the time and in all places expect it to be
a string, not checking if its None first.

The database migration will delete any sources that have a NULL filesystem_id,
plus anything that references those sources.

Discovered by the mypy work I'm doing in #6346.

Refs #6226.
legoktm added a commit that referenced this issue Apr 7, 2022
We already set this field all the time and in all places expect it to be
a string, not checking if its None first.

The database migration will delete any sources that have a NULL filesystem_id,
plus anything that references those sources.

Discovered by the mypy work I'm doing in #6346.

Refs #6226.
legoktm added a commit that referenced this issue Apr 7, 2022
* Upgrade mypy to 0.942 and sqlalchemy-stubs to 0.4. Type stubs are no
  longer bundled with mypy, so we need to explicitly install various
  types-{name} packages.
* Since we need to install extra packages and need other dependencies
  like Flask, move mypy into test-requirements.txt and run it via the
  dev container.
* The main issue spotted by the SQLAlchemy plugin, that
  sources.filesystem_id is nullable, is being fixed in a separate PR:
  #6350.
* Drop the explicit type comments now that mypy can infer them.
* Use `--explicit-package-bases` when running mypy, so it treats the
  securedrop/admin directories as modules regardless of whether
  `__init__.py` files exist. This is needed so the two tests/
  directories don't conflict with each other.
* Add missing return types to all schema changes and the templates that
  generate them.
* In the `create_source_uuid_column` migration, drop the use of
  `quoted_name()`. For some reason mypy doesn't like it, but more
  importantly we don't need it in SQLite and we don't use it in any
  other schema change.
* Make SecureTemporaryFile.write()'s return type match its parent by
  returning the number of bytes that were written.

Fixes #6346.
Fixes #6358.
legoktm added a commit that referenced this issue Apr 12, 2022
We already set this field all the time and in all places expect it to be
a string, not checking if its None first.

The database migration will delete any sources that have a NULL filesystem_id,
plus anything that references those sources.

Discovered by the mypy work I'm doing in #6346.

Refs #6226.
legoktm added a commit that referenced this issue Apr 12, 2022
* Upgrade mypy to 0.942 and sqlalchemy-stubs to 0.4. Type stubs are no
  longer bundled with mypy, so we need to explicitly install various
  types-{name} packages.
* Since we need to install extra packages and need other dependencies
  like Flask, move mypy into test-requirements.txt and run it via the
  dev container.
* The main issue spotted by the SQLAlchemy plugin, that
  sources.filesystem_id is nullable, is being fixed in a separate PR:
  #6350.
* Drop the explicit type comments now that mypy can infer them.
* Use `--explicit-package-bases` when running mypy, so it treats the
  securedrop/admin directories as modules regardless of whether
  `__init__.py` files exist. This is needed so the two tests/
  directories don't conflict with each other.
* Add missing return types to all schema changes and the templates that
  generate them.
* In the `create_source_uuid_column` migration, drop the use of
  `quoted_name()`. For some reason mypy doesn't like it, but more
  importantly we don't need it in SQLite and we don't use it in any
  other schema change.
* Make SecureTemporaryFile.write()'s return type match its parent by
  returning the number of bytes that were written.

Fixes #6346.
Fixes #6358.
legoktm added a commit that referenced this issue Apr 19, 2022
* Upgrade mypy to 0.942 and sqlalchemy-stubs to 0.4. Type stubs are no
  longer bundled with mypy, so we need to explicitly install various
  types-{name} packages.
* Since we need to install extra packages and need other dependencies
  like Flask, move mypy into test-requirements.txt and run it via the
  dev container.
* The main issue spotted by the SQLAlchemy plugin, that
  sources.filesystem_id is nullable, is being fixed in a separate PR:
  #6350.
* Drop the explicit type comments now that mypy can infer them.
* Use `--explicit-package-bases` when running mypy, so it treats the
  securedrop/admin directories as modules regardless of whether
  `__init__.py` files exist. This is needed so the two tests/
  directories don't conflict with each other.
* Add missing return types to all schema changes and the templates that
  generate them.
* In the `create_source_uuid_column` migration, drop the use of
  `quoted_name()`. For some reason mypy doesn't like it, but more
  importantly we don't need it in SQLite and we don't use it in any
  other schema change.
* Make SecureTemporaryFile.write()'s return type match its parent by
  returning the number of bytes that were written.

Fixes #6346.
Fixes #6358.
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

Successfully merging a pull request may close this issue.

1 participant