Relative Content

Tag Archive for sqlalchemy

creating a task based on data on weekly marks in the next period, how to do this?

activity_mtm_week = Table( “activity_mtm_week”, Base.metadata, Column(“activity_id”, ForeignKey(“activity.id”), primary_key=True), Column(“week_id”, ForeignKey(“week.id”), primary_key=True), ) class Activity(Base): __tablename__ = “activity” id: Mapped[int] = mapped_column(primary_key=True) name: Mapped[str] = mapped_column(String(15)) weeks: Mapped[List[“Week”]] = relationship( secondary=activity_mtm_week, back_populates=”activities” ) activity_days: Mapped[List[“Activity_day”]] = relationship( cascade=”all, delete, delete-orphan” ) class Week(Base): __tablename__ = “week” id: Mapped[int] = mapped_column(primary_key=True) week_day: Mapped[str] = mapped_column(String(2)) activities: Mapped[List[“Activity”]] […]

SQLAlchemy async engine and relationships

I am building a RBAC web app with FastAPI. This led me to model implementation below. Based on it, I wrote some tests to validate the implementation. Among others, I required to get permissions of an user based on current instance. Since model instance would be already available as soon I call the method, I thought, it would be straightforward to call required method to obtain the permissions, like a regular class instance. It did not work, but raised error sqlalchemy.exc.MissingGreenlet: greenlet_spawn has not been called; can't call await_only() here. Was IO attempted in an unexpected place?. ChatGPT suggested me to perform operation as on implementation, which worked, but made me a bit sad on limitations of the library for async operations. I step further would be to use a more adequate library SQLModel (or even this async-SQLModel) as a substitute, but I feel not so comfortable about that. Had you the same experience with async engine so far?

flask won’t let me import sql alchemy

every time I try to run my flask app I keep getting “cannot import name ‘SQLAlchemy’ from ‘flask’ “(/Users/glitxh/LETSFIXPHONES/.repair/lib/python3.12/site-packages/flask/init.py)