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

Fix assigning expressions to Mapped attributes. #69

Merged
merged 1 commit into from
May 5, 2021

Conversation

MaicoTimmerman
Copy link
Contributor

Description

Allow for assigning expressions to mapped attributes. Fixes #68.

I tried to use ColumnElement[_T], however since sqlalchemy.sql.operators.ColumnOperators all return ClauseElement, this is not possible. Perhaps the operators need to return ColumnElement?

Used test-file:

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

mapper_registry: registry = registry()

e = create_engine('sqlite:///database.db')


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


with Session(e) as s:
    a = A(integer=1)
    a.integer = A.integer + 1
    a.date_time = now()
    s.add(a)
    s.commit()

Checklist

This pull request is:

  • A documentation / typographical error fix
    • Good to go, no issue or tests are needed
  • A short code fix
    • please include the issue number, and create an issue if none exists, which
      must include a complete example of the issue. one line code fixes without an
      issue and demonstration will not be accepted.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests. one line code fixes without tests will not be accepted.
  • A new feature implementation
    • please include the issue number, and create an issue if none exists, which must
      include a complete example of how the feature would look.
    • Please include: Fixes: #<issue number> in the commit message
    • please include tests.

Have a nice day!

@MaicoTimmerman MaicoTimmerman marked this pull request as draft April 29, 2021 15:40
@MaicoTimmerman MaicoTimmerman marked this pull request as ready for review May 5, 2021 16:57
@bryanforbes bryanforbes merged commit afe5bb4 into sqlalchemy:master May 5, 2021
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 this pull request may close these issues.

Assigning functions to orm attributes
2 participants