fix: relative import with no parent package

v0.4
rrr-marble 3 years ago
parent 1adddacf70
commit 994ca85172

@ -4,7 +4,16 @@ from sqlalchemy import Column, Computed, DateTime, Float, Index, Integer, String
# https://sqlalchemy-utils.readthedocs.io/en/latest/_modules/sqlalchemy_utils/types/ts_vector.html # https://sqlalchemy-utils.readthedocs.io/en/latest/_modules/sqlalchemy_utils/types/ts_vector.html
from sqlalchemy.dialects.postgresql import TSVECTOR from sqlalchemy.dialects.postgresql import TSVECTOR
from .database import Base
# to correctly work with both alembic and fastapi we have to check
# if we are run as a module or as a script
# https://stackoverflow.com/questions/14132789/relative-imports-for-the-billionth-time/14132912
import sys
parent_module = sys.modules['.'.join(__name__.split('.')[:-1]) or '__main__']
if __name__ == '__main__' or parent_module.__name__ == '__main__':
from database import Base
else:
from .database import Base
class Header(Base): class Header(Base):

Loading…
Cancel
Save