I have an app with multiple small modules, its with fastapi (python) and vue as the frontend.
I added a new module which uses SQLAlchemy, and then declare classes for tables using table reflection (metadata.reflect and table=metadata.tables[‘mytable’]
)
Because its a small module in the app, I dont want it to fail the entire program, so I have some db init function which try to connect to db and manage failures (with retry option in the ui) so all other modules will still work.
The issue that I have is with the class definition, because if the connection fails the class definition fails.
I tries to use .get(‘mytable’) but it also fails if its null.
Ive tried to define some fake table and use .get(‘mytable’) or Table(‘faketable’…)
But the issue is that if connection fails at first, the colums of the fake tables take effect and after connecting successfully, the columns dont update to the columns of ‘mytable’.
I thought about 2 options:
- Define the classes in a function and call that function on successful init.
- “Update” or “refresh” the classes after successful init (but I dont know how to do it.
Hod Ben Shahal is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.