jowilf / sqlalchemy-file

SQLAlchemy-file is a SQLAlchemy extension for attaching files to SQLAlchemy model and uploading them to various storage such as Local Storage, Amazon S3, Rackspace CloudFiles, Google Storage and others using Apache Libcloud.
https://jowilf.github.io/sqlalchemy-file/
MIT License
95 stars 12 forks source link

Optionally avoid global event hooks #55

Open adscib opened 1 year ago

adscib commented 1 year ago

I played around with the library a bit and found that I can customize different behaviors by subclassing the sqlalchemy-file classes. I can do it without modifying the library code at all, the only thing that trips me is the global setup for event hooks. Is there any chance there could be an option to disable this global setup, or at least remove the hooks after loading the module? It would make the library quite a bit more flexible. In particular, #54 could be implemented externally. I'm not sure what's the right mechanism for that that's backwards compatible, though.

jowilf commented 1 year ago

Yes, I tried to make it easier to override File class for a custom logic. But you need to specify upload_type when declaring your FileField.

Column(FileField(upload_type=MyCustomFileClass))

I can add an option to disable/enable the changes tracking. But this can lead to inconsistencies between your database and your object storage.

adscib commented 1 year ago

Indeed, I can subclass File and that works very well. I would also like to subclass StorageManager, but I don't see a way to update event hooks to use that subclass instead, so I was thinking if there was an option not to register them automatically, I could do that manually with my subclass instead.