Giter Site home page Giter Site logo

Comments (6)

miguelgrinberg avatar miguelgrinberg commented on August 23, 2024 1

Ah, right! db.Session is a method that returns an instance of db.session_class, so yeah, what you did is what I intended to suggest.

from alchemical.

collinsmarra avatar collinsmarra commented on August 23, 2024

How do I track session changes with events?

I am trying to use elastic search for my app. So I was reading the micro-blog tutorial and it use flask-sqlalchemy. So events are implemented this way:

image

I was trying to do the same with alchemical but I cannot use sqlalchemy.events because that would result in RuntimeError: Working outside of application context.

from alchemical.

miguelgrinberg avatar miguelgrinberg commented on August 23, 2024

I'm not sure what is the usage that gives you working outside of app context, but Alchemical does not try to override SQLAlchemy as much as Flask-SQLAlchemy does. Setting events is done directly through SQLAlchemy, as documented here: https://docs.sqlalchemy.org/en/14/core/event.html#event-registration.

from alchemical.

collinsmarra avatar collinsmarra commented on August 23, 2024

image

I think that would be the line that causes the error

from alchemical.

miguelgrinberg avatar miguelgrinberg commented on August 23, 2024

You are using db.session outside of a request. The session does not exist then. I doubt that would even work with Flask-SQLAlchemy, you can't use the session in the global scope. For Alchemical, I think you should be able to pass the session class here, db.Session (uppercase S).

Note: it does actually work with Flask-SQLAlchemy.

from alchemical.

collinsmarra avatar collinsmarra commented on August 23, 2024

Thanks. db.Session (uppercase) would result in an error No such event 'before_commit' for target.
However db.session_class works. I am yet to investigate and learn. Thanks again

from alchemical.

Related Issues (14)

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.