Viicos commented on PR #44249:
URL: https://github.com/apache/airflow/pull/44249#issuecomment-2491919741

   We're going to release 2.10.1 any minute now.
   
   We got [a report](https://github.com/pydantic/pydantic/issues/10924) today 
of an issue happening on Python <3.10. The 
[`TaskInstancePydantic`](https://github.com/apache/airflow/blob/1307e37bc6338c43aa5099752d012e244f8494ba/airflow/serialization/pydantic/taskinstance.py#L84)
 class is subclassing 
[`LoggingMixin`](https://github.com/apache/airflow/blob/main/airflow/utils/log/logging_mixin.py#L68).
 This class has an annotation for `_log` using the new 3.10+ union syntax. 
While Pydantic has always evaluated _all_ type annotations of models including 
their bases, we were not using the correct globals and locals to so. Meaning 
with the following example:
   
   *a.py*
   
   ```python
   from logging import Logger
   
   class Base:
       _log: 'Logger | None'
   ```
   
   *b.py*
   
   ```python
   from a import Base
   
   from pydantic import BaseModel
   
   class Model(BaseModel, Base):
       pass
   ```
   
   Evalutating the annotation for `_log` would have resulted in a `NameError`, 
because `Logger` is imported in `a.py`, and we only used the globals of the 
`b.py` module until now. `NameError`'s are ignored to allow for types to be 
defined later on. However, on 2.10, this now raises a `TypeError` because 
`'Logger | None'` successfully evaluates, but the union syntax is not supported 
on Python 3.9.
   
   What's probably best is to make sure you're using the old syntax for every 
class that is going to be used in the context of a Pydantic model.
   
   


-- 
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]

Reply via email to