Skip to content

Commit

Permalink
Revert "Continuing flask-support for flask-sqlalchemy 3"
Browse files Browse the repository at this point in the history
This reverts commit f35377e.
  • Loading branch information
Harshit Gupta committed Mar 11, 2024
1 parent 131b186 commit 5a1643b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 44 deletions.
54 changes: 13 additions & 41 deletions flask_appbuilder/models/sqla/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
import logging
import re

try:
from flask_sqlalchemy import DefaultMeta, Model as FSQLAlchemyModel
except ImportError:
from flask_sqlalchemy.model import ( # noqa
DefaultMeta,
Model as FSQLAlchemyModel,
)
from flask_sqlalchemy import SQLAlchemy

from flask_sqlalchemy import (
_QueryProperty,
DefaultMeta,
get_state,
SessionBase,
SignallingSession,
SQLAlchemy,
)
from sqlalchemy import orm

try:
from sqlalchemy.ext.declarative import as_declarative, declarative_base
from sqlalchemy.ext.declarative import as_declarative
except ImportError:
from sqlalchemy.ext.declarative.api import as_declarative # noqa
from sqlalchemy.ext.declarative.api import as_declarative

try:
from sqlalchemy.orm.util import identity_key # noqa
Expand Down Expand Up @@ -102,7 +102,8 @@ class ModelDeclarativeMeta(DefaultMeta):
"""


class BaseModel:
@as_declarative(name="Model", metaclass=ModelDeclarativeMeta)
class Model(object):
"""
Use this class has the base for your models,
it will define your table names automatically
Expand Down Expand Up @@ -131,35 +132,6 @@ def to_json(self):
return result


Model = declarative_base(cls=BaseModel, metaclass=ModelDeclarativeMeta, name="Model")


class SQLA(SQLAlchemy):
"""
This is a child class of flask_SQLAlchemy
It's purpose is to override the declarative base of the original
package. So that it is bound to F.A.B. Model class allowing the dev
to be in the same namespace of the security tables (and others)
and can use AuditMixin class alike.
Use it and configure it just like flask_SQLAlchemy
"""

def __init__(self, *args, **kwargs):
model_class = kwargs.pop("model_class", Model)

super().__init__(*args, model_class=model_class, **kwargs)

def get_tables_for_bind(self, bind=None):
"""Returns a list of all tables relevant for a bind."""
result = []
tables = Model.metadata.tables
for key in tables:
if tables[key].info.get("bind_key") == bind:
result.append(tables[key])
return result


"""
This is for retro compatibility
"""
Expand Down
5 changes: 2 additions & 3 deletions flask_appbuilder/security/sqla/models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import datetime

from flask import g
from flask_appbuilder import Model
from flask_appbuilder._compat import as_unicode

from sqlalchemy import (
Boolean,
Column,
Expand All @@ -18,6 +15,8 @@
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.orm import backref, relationship

from ... import Model
from ..._compat import as_unicode

_dont_audit = False

Expand Down

0 comments on commit 5a1643b

Please sign in to comment.