File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -212,8 +212,6 @@ def pagination(self) -> PaginationQueryStringManager:
212212
213213 return pagination
214214
215- # TODO: finally use this! upgrade Sqlachemy Data Layer
216- # and add to all views (get list/detail, create, patch)
217215 @property
218216 def fields (self ) -> Dict [str , List [str ]]:
219217 """
@@ -238,8 +236,7 @@ def fields(self) -> Dict[str, List[str]]:
238236 msg = f"Application has no resource with type { resource_type !r} "
239237 raise InvalidType (msg )
240238
241- schema : Type [BaseModel ] = RoutersJSONAPI .all_jsonapi_routers [resource_type ]._schema
242- self ._get_schema (resource_type )
239+ schema : Type [BaseModel ] = self ._get_schema (resource_type )
243240
244241 for field_name in field_names :
245242 if field_name == "" :
@@ -255,8 +252,7 @@ def fields(self) -> Dict[str, List[str]]:
255252 return {resource_type : set (field_names ) for resource_type , field_names in fields .items ()}
256253
257254 def _get_schema (self , resource_type : str ) -> Type [BaseModel ]:
258- target_router = RoutersJSONAPI .all_jsonapi_routers [resource_type ]
259- return target_router .detail_response_schema
255+ return RoutersJSONAPI .all_jsonapi_routers [resource_type ]._schema
260256
261257 def get_sorts (self , schema : Type ["TypeSchema" ]) -> List [Dict [str , str ]]:
262258 """
Original file line number Diff line number Diff line change @@ -318,6 +318,32 @@ async def test_select_custom_fields_with_includes(
318318 ),
319319 }
320320
321+ async def test_select_custom_fields_for_includes_without_requesting_includes (
322+ self ,
323+ app : FastAPI ,
324+ client : AsyncClient ,
325+ user_1 : User ,
326+ ):
327+ url = app .url_path_for ("get_user_list" )
328+
329+ params = QueryParams ([("fields[post]" , "title" )])
330+ response = await client .get (url , params = str (params ))
331+
332+ assert response .status_code == status .HTTP_200_OK , response .text
333+ response_data = response .json ()
334+
335+ assert response_data == {
336+ "data" : [
337+ {
338+ "attributes" : UserAttributesBaseSchema .from_orm (user_1 ),
339+ "id" : str (user_1 .id ),
340+ "type" : "user" ,
341+ },
342+ ],
343+ "jsonapi" : {"version" : "1.0" },
344+ "meta" : {"count" : 1 , "totalPages" : 1 },
345+ }
346+
321347
322348class TestCreatePostAndComments :
323349 async def test_get_posts_with_users (
You can’t perform that action at this time.
0 commit comments