Skip to content

Commit 6a97234

Browse files
committed
fix: Fixed get_admin_or_create internal logic
1 parent 3d54266 commit 6a97234

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

fastapi_amis_admin/admin/admin.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,13 +1343,14 @@ def get_admin_or_create(
13431343
nested: bool = True,
13441344
) -> Optional[BaseAdminT]:
13451345
"""Get or create admin instance"""
1346-
admin = self._registered.get(admin_cls, None)
1347-
if admin is None and nested:
1348-
admin = self._get_admin_or_create_nested(admin_cls)
1346+
admin = self._registered.get(admin_cls, False)
1347+
if admin is False:
1348+
if nested:
1349+
admin = self._get_admin_or_create_nested(admin_cls)
1350+
if not admin and (not register or self.__register_lock):
1351+
return None
13491352
if admin:
13501353
return admin
1351-
if not register or self.__register_lock:
1352-
return None
13531354
# create admin instance
13541355
admin = admin_cls(self)
13551356
self._registered[admin_cls] = admin
@@ -1402,6 +1403,8 @@ def get_model_admin(self, table_name: str) -> Optional[ModelAdmin]:
14021403
if not issubclass(admin_cls, (ModelAdmin, AdminApp)):
14031404
continue
14041405
admin = self.get_admin_or_create(admin_cls, register=False)
1406+
if admin is None:
1407+
continue
14051408
if issubclass(admin_cls, ModelAdmin) and admin.bind_model and admin.model.__table__.name == table_name:
14061409
return admin
14071410
elif isinstance(admin, AdminApp) and self.engine is admin.engine:

0 commit comments

Comments
 (0)