Declared attributes aren't supported
See original GitHub issueI’m using SQLAlchemy’s declared_attr
decorator to add columns and relationships.
However, the decorated columns and relationships are completely ignored.
Here is a very simplified reproducer:
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.ext.declarative.api import declared_attr
from sqlalchemy.orm import relationship
from sqlalchemy.schema import Column, ForeignKey
from sqlalchemy.types import Integer
Base = declarative_base()
class Person(Base):
__tablename__ = 'people'
id = Column(Integer, primary_key=True)
class EmailAddress(Base):
__tablename__ = 'emails'
@declared_attr
def owner_id(self) -> Column:
return Column(Integer, ForeignKey('people.id'), nullable=False)
@declared_attr
def owner(self) -> relationship:
return relationship(Person)
me = Person()
email_address = EmailAddress(owner=me)
This is what mypy says:
$ pipenv run mypy decl_attr.py
decl_attr.py:30: error: Unexpected column "owner" for model "EmailAddress"
Issue Analytics
- State:
- Created 4 years ago
- Reactions:12
- Comments:7 (2 by maintainers)
Top Results From Across the Web
xml validation failed with attribute required and attribute not ...
the problem is that the attribute id has been declared global(direct child of xs:schema). therefore, the attribute id should be qualified ...
Read more >"The 'MaxOccurs' attribute is not supported in this context ... - IBM
Symptom. "The 'MaxOccurs' attribute is not supported in this context" when attempting to create a new map using an XML Schema.
Read more >Tools attributes reference | Android Studio
Android Studio supports a variety of XML attributes in the tools namespace that enable design-time features or compile-time behaviors.
Read more >Attributes in Clang — Clang 16.0.0git documentation
Specified values violate subtarget specifications;; Specified values are not compatible with values provided through other attributes.
Read more >Error Explanations for The W3C Markup Validation Service
You have used the attribute named above in your document, but the document type you are using does not support that attribute for...
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
Any updates on this feature request?
@wbobeirne thanks for trying it out and your feedback
As a sidenote In editor Pylance type checking sometimes produces errors due to lack of mypy plugin support. Is mypy producing the same errors when ran on this file?
This is an expunged version of the solution I use in our codebase. The following code runs in production and passes mypy and pylance.
See the hover tooltip