Skip to content

Flask-SQLAlchemy 3.x will cause errors in unit testing #219

Description

@jinmiaoluo

Latest Flask-SQLAlchemy will cause an error when running make test. The error message is as follows:

self = <SQLAlchemy sqlite:////home/jinmiaoluo/repo/arch-security-tracker/tracker.db>, name = 'create_scoped_session'                                                                                                                                                                                                                                  def __getattr__(self, name: str) -> t.Any:                                                                                                                           
        if name == "db":                                                            
            import warnings                                                         
                           
            warnings.warn(                                                          
                "The 'db' attribute is deprecated and will be removed in"                                                                                                
                " Flask-SQLAlchemy 3.1. The extension is registered directly as"                                                                                         
                " 'app.extensions[\"sqlalchemy\"]'.",                           
                DeprecationWarning,                                                 
                stacklevel=2,      
            )                
            return self
                       
        if name == "relation":
            return self._relation
                                 
        if name == "event":
            return sa.event
                           
        if name.startswith("_"):
            raise AttributeError(name)
                                      
        for mod in (sa, sa.orm):
            if hasattr(mod, name):
                return getattr(mod, name)
     
>       raise AttributeError(name)
E       AttributeError: create_scoped_session

.venv/lib/python3.11/site-packages/flask_sqlalchemy/extension.py:1005: AttributeError

Rolling back Flask-SQLAlchemy to 2.5.x allows unit tests to run smoothly.

diff --git a/requirements.txt b/requirements.txt
index 9519529..8c81793 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,6 +1,6 @@
 Flask
 Flask-Login
-Flask-SQLAlchemy
+Flask-SQLAlchemy~=2.5.0
 Flask-Migrate
 Flask-WTF
 flask-talisman

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions