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

Assigning functions to orm attributes #68

Closed
MaicoTimmerman opened this issue Apr 22, 2021 · 1 comment · Fixed by #69
Closed

Assigning functions to orm attributes #68

MaicoTimmerman opened this issue Apr 22, 2021 · 1 comment · Fixed by #69
Labels
bug Something isn't working

Comments

@MaicoTimmerman
Copy link
Contributor

MaicoTimmerman commented Apr 22, 2021

Describe the bug
Introduced by #40, sql.functions are no longer able to be assigned to ORM attributes. I couldn't find documented cases of directly assigning functions to attributes. Is it even a supported use-case? Or should update() always be used.

Expected behavior
Type checking to pass, as it works at runtime

To Reproduce

from sqlalchemy import Column, DateTime
from sqlalchemy import Integer
from sqlalchemy.orm import registry
from sqlalchemy.sql.functions import now

mapper_registry: registry = registry()

@mapper_registry.mapped
class A:
    __tablename__ = "a"
    id = Column(Integer, primary_key=True)
    date_time = Column(DateTime())

a = A()
a.date_time = now()

Error

test/ext/mypy/files/function_now.py:15: error: Incompatible types in assignment (expression has type "now[<nothing>]", variable has type "Optional[datetime]")```

Have a nice day!

@MaicoTimmerman MaicoTimmerman added the requires triage New issue that requires categorization label Apr 22, 2021
@zzzeek
Copy link
Member

zzzeek commented Apr 22, 2021

@zzzeek zzzeek added bug Something isn't working and removed requires triage New issue that requires categorization labels Apr 22, 2021
@bryanforbes bryanforbes mentioned this issue Apr 22, 2021
3 tasks
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.

2 participants