Code Monkey home page Code Monkey logo

Comments (5)

mocaccano avatar mocaccano commented on June 11, 2024 5

@emmanuelito As mentioned in my comment above, swapping the lines in the try and except blocks will remove the DeprecationWarning:

def get_engine():
    try:
        # this works with Flask-SQLAlchemy>=3
        return current_app.extensions["migrate"].db.engine
    except TypeError:
        # this works with Flask-SQLAlchemy<3 and Alchemical
        return current_app.extensions["migrate"].db.get_engine()

from flask-migrate.

miguelgrinberg avatar miguelgrinberg commented on June 11, 2024 3

This has already been addressed in the latest Flask-Migrate releases, but the problem is that the fix is in the env.py file that is in your migrations directory.

If you haven't made any changes to this file you can just take the updated version from here and drop it in place of the older one.

If you prefer a cleaner approach, then rename your migrations folder to some other name, then create a new migrations repository with flask db init after installing the latest Flask-Migrate, and then finally move all the Python scripts in the older migrations/versions directory to the one you just created.

from flask-migrate.

miguelgrinberg avatar miguelgrinberg commented on June 11, 2024 1

I don't think it is worth making any changes at this point. The get_engine() will be removed in 3.1 and the deprecation warning will not appear anymore. If this warning bothers you, feel free to edit your env.py.

from flask-migrate.

mokadevcloud avatar mokadevcloud commented on June 11, 2024

Awesome, thanks for the quick response!
Couple of minor improvements possible in env.py:

  1. add docstrings to get_engine() and get_engine_url()
  2. get_engine() has the older version in the try block and the new version in the except block, while it is the opposite in get_engine_url(). I think we can consistently use the latter order.

Thanks again.

from flask-migrate.

emmanuelito avatar emmanuelito commented on June 11, 2024

Thanks !
I think that the approach

def get_engine():
    try:
        # this works with Flask-SQLAlchemy<3 and Alchemical
        return current_app.extensions["migrate"].db.get_engine()
    except TypeError:
        # this works with Flask-SQLAlchemy>=3
        return current_app.extensions["migrate"].db.engine

does not eliminate the DeprecationWarning.

Because currently get_engine is ok but raise the warning.

Maybe better to check flask_sqlalchemy.__version__[0] ?

from flask-migrate.

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.