-
Notifications
You must be signed in to change notification settings - Fork 14.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate expected types for args for DAG, BaseOperator and TaskGroup #40269
Conversation
ad1acfa
to
86e6b17
Compare
86e6b17
to
5b2765d
Compare
Generally looks good to me, except I think we don’t need to declare the types in a separate dict, but can use Most of the entries should be simple, only |
I did try to get the type hints using |
That makes sense, getting annotations at runtime (instead of in Mypy) is something Python has been working in recently but I was not sure exactly when it became usable. Looks like we can’t do that yet (maybe two years later…) Let’s extract the dicts and checks outside the classes, and add a todo comment that says maybe consider refactoring when we require 3.10+ (not sure about the exact version but we don’t need to be exact) |
@uranusjr, could you clarify where exactly we should extract the validation logic? Do you mean move the dicts to be within the same module but outside the classes? The arguments we validate are specific to certain classes (DAG, BaseOperator, TaskGroup) and vary across them. Moreover, since these argument values could be passed directly or via default arguments, we perform the validation check after the instance has been assigned all argument values, following the evaluation of positional/keyword arguments and default arguments. In my opinion, keeping these dicts localized within their respective classes is better. However, if you could explain where and why we should extract them, it would help me understand your perspective better. Also, the helper validation method is already outside the classes in utils which we call from the respective classes. |
Your correct checks are fine, I just want to move the dicts out of the classes, and add comments to hint about future refactors (and to stop people from refactoring before the supported Python versions allow us to). |
@uranusjr okay, moved the dicts out and added comments as suggested. Please review when possible, thanks. |
my suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to add a pre-commit hook to ensure the dicts are up-to-date with the __init__
arguments. But this lgtm.
I will dwelve into this later to check if we can curtail the attrs list and/or if we have a good library that could help us. For now, would like to merge this and have a preventive workaround for crashes we're seeing users reporting. |
…pache#40269) Validates that some commonly used arguments by DAG authors conform to the expected types. If the provided values do not match the expected types, a TypeError is raised, resulting in DAG import errors that appear in the Airflow UI. Closes: apache#40187
Validates that some commonly used arguments by DAG authors
conform to the expected types. If the provided values do not
match the expected types, a TypeError is raised, resulting in
DAG import errors that appear in the Airflow UI.
Closes: #40187
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in newsfragments.