diff --git a/fastapi_amis_admin/crud/_sqlalchemy.py b/fastapi_amis_admin/crud/_sqlalchemy.py index 6af162d..55278a1 100644 --- a/fastapi_amis_admin/crud/_sqlalchemy.py +++ b/fastapi_amis_admin/crud/_sqlalchemy.py @@ -316,8 +316,10 @@ def _create_schema_filter(self) -> Type[SchemaFilterT]: ) def _create_schema_read(self) -> Optional[Type[SchemaReadT]]: - if not self.read_fields: + if self.read_fields is None: return None + # Set the read fields to the schema update if not provided + self.read_fields = self.read_fields or model_fields(self.schema_update) # Filter out any non-model fields from the read fields modelfields = self.parser.filter_modelfield(self.read_fields) # Create the schema using the model fields diff --git a/fastapi_amis_admin/crud/base.py b/fastapi_amis_admin/crud/base.py index 7d8ff1b..4db7409 100644 --- a/fastapi_amis_admin/crud/base.py +++ b/fastapi_amis_admin/crud/base.py @@ -81,8 +81,8 @@ def register_crud( self.schema_list = schema_list or self.schema_list or self._create_schema_list() self.schema_filter = schema_filter or self.schema_filter or self._create_schema_filter() self.schema_create = schema_create or self.schema_create or self._create_schema_create() - self.schema_read = schema_read or self.schema_read or self._create_schema_read() self.schema_update = schema_update or self.schema_update or self._create_schema_update() + self.schema_read = schema_read or self.schema_read or self._create_schema_read() self.list_per_page_max = list_per_page_max or self.list_per_page_max self.paginator = Paginator(perPageMax=self.list_per_page_max) self.router.add_api_route( diff --git a/tests/test_crud/test_SqlalchemyCrud_fields.py b/tests/test_crud/test_SqlalchemyCrud_fields.py index 27e0ef5..ea96393 100644 --- a/tests/test_crud/test_SqlalchemyCrud_fields.py +++ b/tests/test_crud/test_SqlalchemyCrud_fields.py @@ -364,6 +364,7 @@ class ArticleCrud(SqlalchemyCrud): async def test_read_fields_and_schema_read_is_none(app: FastAPI, models): class ArticleCrud(SqlalchemyCrud): router_prefix = "/article" + read_fields = None ins = ArticleCrud(models.Article, db.engine).register_crud()