jason810496 commented on code in PR #76537: URL: https://github.com/apache/airflow/pull/76537#discussion_r4501837821
########## airflow-core/tests/unit/api_fastapi/test_lazy_response_fields.py: ########## @@ -0,0 +1,299 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Guard against response fields that pydantic validates lazily. + +Pydantic validates an ``Iterable[...]`` field lazily, while FastAPI serializes the +response on the event loop: each item's attributes are then resolved there, on the sync +engine, so a lazy relationship or a ``selectin`` post-load becomes a query that blocks +the whole API server once the connection pool is busy. ``list[...]`` validates on +construction, inside the route, and renders to the same ``type: array`` in the OpenAPI +schema, so there is no reason to declare one of these fields lazily. + +Every pydantic model under ``airflow.api_fastapi`` is checked, not only the collection +responses: the hazard is the annotation, not the name of the class holding it. A model +defined inside a function is out of reach, and so is a response model that lives outside +the package, such as one belonging to a provider's auth manager app. + +The fields that predate this test are listed in +``generated/known_lazy_response_fields.txt`` as strict xfails. The collection ones are +tracked for migration in #76425. Review Comment: It seems like wrong issue id? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
