Skip to content

Commit 13fc7fd

Browse files
NightMarcherNightMarcher
authored and
NightMarcher
committed
feat: check model of Manager and table of model.Meta first
1 parent d5e6a5f commit 13fc7fd

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

fastapi_esql/orm/base_app.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,19 @@
33

44
class AppMetaclass(ABCMeta):
55

6+
def __new__(cls, name, bases, attrs):
7+
if name != "BaseManager":
8+
model = attrs.get("model")
9+
if not model:
10+
raise NotImplementedError(f"Class attribute `model` was not defined by {name}!")
11+
12+
table = getattr(model.Meta, "table", None)
13+
if not table:
14+
raise NotImplementedError(f"Meta attribute `table` was not defined by model {model.__name__}!")
15+
16+
attrs["table"] = model.Meta.table
17+
return super().__new__(cls, name, bases, attrs)
18+
619
@property
720
def ro_conn(self):
821
"""
@@ -20,10 +33,3 @@ def rw_conn(self):
2033
if not getattr(self, "get_rw_conn", None):
2134
raise NotImplementedError(f"Method `get_rw_conn()` was not implemented by {self.__class__.__name__}!")
2235
return self.get_rw_conn()
23-
24-
@property
25-
def table(self):
26-
db_table = self.model._meta.db_table
27-
if not db_table:
28-
raise NotImplementedError(f"Class attribute `model` was not defined by {self.__name__}!")
29-
return db_table

0 commit comments

Comments
 (0)