Infer type for dialects.postgresql.UUID(as_uuid=True)
See original GitHub issueIs your feature request related to a problem? Please describe.
from sqlalchemy import Column, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import declarative_base
Base = declarative_base()
UUIDC = UUID(as_uuid=True)
class Foo(Base):
id = Column(UUIDC)
bar_id = Column(UUIDC, ForeignKey("bars.id"))
This will yield the following errors:
$ mypy --strict testuuidc.py
testuuidc.py:10: error: Need type annotation for 'id'
testuuidc.py:11: error: [SQLAlchemy Mypy plugin] Can't infer type from ORM mapped expression assigned to attribute 'bar_id'; please specify a Python type or Mapped[<python type>] on the left hand side.
Found 2 errors in 1 file (checked 1 source file)
Describe the solution you’d like
I wonder if thanks to the plugin, mypy wouldn’t be able to infer the uuid.UUID
type from the postgresql.UUID(as_uuid=True)
definition.
Describe alternatives you’ve considered
Obviously, we can always provide the typing explicitly.
Have a nice day!
Thanks a lot for the amazing work on sqlalchemy!
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How can I use UUIDs in SQLAlchemy? - Stack Overflow
The sqlalchemy postgres dialect supports UUID columns. This is easy (and the question is specifically postgres) -- I don't understand why the other...
Read more >PostgreSQL UUID type, Python's UUID — and type hints
I looked into the implementation of the dialect's UUID whether it implements a constructor which takes a Python UUID, but no luck. Given...
Read more >Documentation: 15: 8.12. UUID Type - PostgreSQL
The data type uuid stores Universally Unique Identifiers (UUID) as defined by RFC 4122, ISO/IEC 9834-8:2005, and related standards.
Read more >GUID Type - FastAPI Utilities
In particular, the postgres-compatible UUID type provided by sqlalchemy ( sqlalchemy.dialects.postgresql.UUID ) will not work with other databases, ...
Read more >PostgreSQL - UUID Data Type - GeeksforGeeks
PostgreSQL – UUID Data Type ... UUID is an abbreviation for Universal Unique Identifier defined by RFC 4122 and has a size of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Actually, providing the typing explictly fails:
This yields the following errors:
Mike Bayer has proposed a fix for this issue in the main branch:
add typing for PG UUID, other types https://gerrit.sqlalchemy.org/c/sqlalchemy/sqlalchemy/+/3870