Giter VIP home page Giter VIP logo

Comments (5)

MitPitt avatar MitPitt commented on September 25, 2024 1

@sion908 I am introducing litestar to a project which already had sqlalchemy in it. I would like to keep new litestar code separated from older sqlalchemy stuff. Meaning I don't want to import AuditColumns from litestar. In case I wanted to remove litestar from the project in the future, this would create problems.

But I will try using lambda: datetime.now(), thanks.

from litestar.

provinzkraut avatar provinzkraut commented on September 25, 2024 1

Closing this as it's not really a bug. Thanks @sion908 for providing the explanation and alternative solution :)

from litestar.

sion908 avatar sion908 commented on September 25, 2024

@MitPitt
Hi!!
I also encountered the same error.
And this seems to be an expected error.
As a concept like a responsibility branching point, it seems better not to let the db generate values ​​as much as possible, so use lambda: datetime.now(timezone.utc) instead of func.nou(). However, in this case, I think it can be said that it is good.

like this
And it's in hereadvanced-alchemy

class AuditColumns:
    """Created/Updated At Fields Mixin."""

    created_at: Mapped[datetime] = mapped_column(
        DateTimeUTC(timezone=True),
        default=lambda: datetime.now(timezone.utc),
    )
    """Date/time of instance creation."""
    updated_at: Mapped[datetime] = mapped_column(
        DateTimeUTC(timezone=True),
        default=lambda: datetime.now(timezone.utc),
    )
    """Date/time of instance last update."""

you can import from here

from litestar.plugins.sqlalchemy import AuditColumns

from litestar.

sion908 avatar sion908 commented on September 25, 2024

I hope it was helpful

from litestar.

provinzkraut avatar provinzkraut commented on September 25, 2024

@sion908 I am introducing litestar to a project which already had sqlalchemy in it. I would like to keep new litestar code separated from older sqlalchemy stuff. Meaning I don't want to import AuditColumns from litestar. In case I wanted to remove litestar from the project in the future, this would create problems.

You can just import it from advanced-alchemy directly:

from advanced_alchemy.base import AuditColumn

from litestar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.