-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Initalizing file_upload with subclassed SQLAlchemy instance? #97
Comments
I managed to get it running by simply adding a constructor with a super function for inheritance - e.g.
Now to dive in and start working with it. Thanks again. |
Ugh, spoke too soon - forgot I'd commented out the file_upload.Model decorator. Still getting the same error. |
@GhastlyParadox Hi |
Hi Joe, just getting back to work after a long weekend, and saw you replied. Many thanks! |
Hi @GhastlyParadox , it looks like the To confirm this, can you run this please:
And post the output here, thank you |
Hi Joe, I am using Flask-Sqlalchemy now, but my models are currently set up using a raw declarative_base - e.g. But the db instance itself is Flask-Sqlalchemy. I actually wondered whether I needed to be using Flask-Sqlalchemy db.Model as well, for the full Flask-Sqlalchemy configuration, in order to get this working. So I tried that -- it took some restructuring to avoid circular imports -- but in the end, once I got everything working with db.Model, I got the same result/error. So I went back to just using That said, my current
|
Sorry for the delay @GhastlyParadox i'm going to pick this issue up today... |
Yes, you must pass I'm going to provide details and any required fixes to port FFU to be able to work with vanilla SqlAlchemy as well. This issue will be related to this new feature so please keep this open until the fix & or documentation is updated... ill pick this up tomorrow morning, thanks. |
this is being fixed in #99 |
Initalizing file_upload with subclassed SQLAlchemy instance? #97
Initalizing file_upload with subclassed SQLAlchemy instance? #97
Initalizing file_upload with subclassed SQLAlchemy instance? #97
Hi Joe,
First, thank you for developing this. Provided I can get it working in my project, it'd be perfect for my needs. I'm working on an image manager feature for an existing Flask application with a rather large/complex MySQL database setup that serves as a REST API. While the database itself is a beast, for this project I'm really only dealing with a single table that has no relationships.
The database had been set up using raw SQLAlchemy, but I reconfigured it using Flask-SQLAlchemy, in hopes to get it working with flask-file-upload. So far though, I'm having trouble initializing it, getting the following error:
Traceback (most recent call last): File "/Users/aglane/Box Sync/Git/flora-DEV/herbflask/__init__.py", line 1, in <module> from application import create_app File "/Users/aglane/Box Sync/Git/flora-DEV/herbflask/application/__init__.py", line 32, in <module> from .db.miflora import MIFloraDB File "/Users/aglane/Box Sync/Git/flora-DEV/herbflask/application/db/miflora.py", line 1113, in <module> class ImagesDev(MIFLORA_BASE): File "/Users/aglane/Box Sync/Git/flora-DEV/env/lib/python3.7/site-packages/flask_file_upload/model.py", line 50, in __new__ new_cols_list, filenames_list = _ModelUtils.get_attr_from_model(instance, new_cols, filenames, db) File "/Users/aglane/Box Sync/Git/flora-DEV/env/lib/python3.7/site-packages/flask_file_upload/_model_utils.py", line 123, in get_attr_from_model new_cols.append(_ModelUtils.columns_dict(attr, db)) File "/Users/aglane/Box Sync/Git/flora-DEV/env/lib/python3.7/site-packages/flask_file_upload/_model_utils.py", line 90, in columns_dict create_col File "/Users/aglane/Box Sync/Git/flora-DEV/env/lib/python3.7/site-packages/flask_file_upload/_model_utils.py", line 36, in create_keys col_dict[key] = fn(key, key) File "/Users/aglane/Box Sync/Git/flora-DEV/env/lib/python3.7/site-packages/flask_file_upload/_model_utils.py", line 86, in create_col return db.Column(db.String(str_len), key=key, name=name) AttributeError: 'NoneType' object has no attribute 'Column'
It seems as though the database isn't being recognized as an SQLAlchemy instance?
I'm wondering whether this may be because I've subclassed the SQLAlchemy instance with a MIFloraDB class, which handles all the query logic for the REST API - e.g.
from flask_sqlalchemy import SQLAlchemy
class MIFloraDB(SQLAlchemy):
...
Which I then import into my application (app factory) to create the SQLAlchemy instance:
flora_db = MIFloraDB()
def create_app():
with app.app_context():
flora_db.init_app(app)
file_upload.init_app(app, flora_db)
return app
Everything else seems to be configured properly, so that's my best guess at this point, but any thoughts/suggestions very much appreciated!
The text was updated successfully, but these errors were encountered: