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

[Bug] Artifact schemas are inferred to be incorrect types #10442

Closed
2 tasks done
nakamichiworks opened this issue Jul 14, 2024 · 4 comments · Fixed by #10443
Closed
2 tasks done

[Bug] Artifact schemas are inferred to be incorrect types #10442

nakamichiworks opened this issue Jul 14, 2024 · 4 comments · Fixed by #10443
Labels
bug Something isn't working

Comments

@nakamichiworks
Copy link
Contributor

nakamichiworks commented Jul 14, 2024

Is this a new bug in dbt-core?

  • I believe this is a new bug in dbt-core
  • I have searched the existing issues, and I could not find an existing issue for this bug

Current Behavior

I want to use WritableManifest class to parse and analyze manifest.json of my dbt projects.

However, code editor (vscode) and associated type checker (pyright) incorrectly infer the type of WritableManifest to be VersionedSchema, which means that code completion does not work for the fields of the class.

# script.py
import json
from dbt.artifacts.schemas.manifest import WritableManifest

with open("manifest.json") as f:
    data = json.load(f)
    manifest = WritableManifest(**data)
    print(manifest.nodes)
    # vscode warning:
    # Cannot access attribute "nodes" for class "VersionedSchema"
    # Attribute "nodes" is unknownPylance[reportAttributeAccessIssue]
$ pyright script.py
/private/tmp/use_dbt_artifacts/script.py
  /private/tmp/use_dbt_artifacts/script.py:8:20 - error: Cannot access attribute "nodes" for class "VersionedSchema"
    Attribute "nodes" is unknown (reportAttributeAccessIssue)
1 error, 0 warnings, 0 informations

Expected Behavior

Instances of WritableManifest should be inferred to be WritableManifest type.

Steps To Reproduce

See the code snippet above.

Relevant log output

No response

Environment

- OS: macOS 14.5
- Python: 3.12.4
- dbt: 1.8.3

Which database adapter are you using with dbt?

Not relevant for this issue.

Additional Context

No response

@nakamichiworks nakamichiworks added bug Something isn't working triage labels Jul 14, 2024
@dbeatty10
Copy link
Contributor

Thanks for reaching out @nakamichiworks !

We use mypy as our type checker, and when I run your example script with it, it doesn't flag any issues:

$ mypy script.py

Success: no issues found in 1 source file

Could this be an issue with pyright rather than any issue with the way the type annotation is expressed?

@nakamichiworks
Copy link
Contributor Author

Sorry I didn't notice the difference between mypy and pyright. I will look into the difference between the two type checkers in more detail.

That said, my proposal in #10443 can satisfy both mypy and pyright.
The proposed usage of TypeVar for class objects is even suggested in the official mypy docs.
Any reason or concern not to accept my proposal?

@dbeatty10
Copy link
Contributor

Thanks for that info @nakamichiworks -- just let us know what you find out in relation to the difference between mypy and pyright.

We can have one of our engineers take a look at your proposed change in #10443 and see what they think too.

@MichelleArk
Copy link
Contributor

@nakamichiworks thank you for opening this and for for linking the mypy docs! Your proposed change looks good 👍

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

Successfully merging a pull request may close this issue.

3 participants