Caching the result of automap? #11512
-
Is there a way to cache/save the result of the reflect and automap? I tried pickling the
I assume it's because Are there any solutions? Or this has to always happen at runtime and there's no way around that? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Python classes are not pickleable (unless something has changed in py 3.12, 3.13 maybe) and in this case yes those classes are dynamically generated so they are really not directly pickleable - it's still possible in theory for the structure of the attributes on these classes to be serialized, and to create deserialization functions that re-apply these attributes to newly generated classes while skipping the heuristics used in creating and configuring mappers, however SQLAlchemy has nothing like that in place and it would be extremely labor intensive to create and maintain such a system. |
Beta Was this translation helpful? Give feedback.
-
Hi, You can look into sqlacodegen that's an external library that can generate the python code for the classes given the reflected structure. https://github.com/agronholm/sqlacodegen |
Beta Was this translation helpful? Give feedback.
Python classes are not pickleable (unless something has changed in py 3.12, 3.13 maybe) and in this case yes those classes are dynamically generated so they are really not directly pickleable - it's still possible in theory for the structure of the attributes on these classes to be serialized, and to create deserialization functions that re-apply these attributes to newly generated classes while skipping the heuristics used in creating and configuring mappers, however SQLAlchemy has nothing like that in place and it would be extremely labor intensive to create and maintain such a system.