You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2019/04/07 20:27:23 UTC

[GitHub] [airflow] BasPH opened a new pull request #5056: [WIP][AIRFLOW-???] Move remaining models out of models.py

BasPH opened a new pull request #5056: [WIP][AIRFLOW-???] Move remaining models out of models.py
URL: https://github.com/apache/airflow/pull/5056
 
 
   **Currently draft!**
   My own CI is green on all Python 3 jobs, Python 2 jobs are in progress. Made this draft PR because I have some questions to be answered before merging.
   
   ------
   
   This PR finalizes the move of all classes out of the infamous models.py (including test_models.py). It's a big PR since all classes are tightly coupled which made it impossible to move out one by one. Some of the non-straight-forward things to point out:
   
   - To preserve backwards compatibility, `airflow/models/__init__.py` imports all (sub)modules (So you can still import `airflow.models.DAG` instead of `airflow.models.dag.DAG`).
   - Classes `DAG` and `DagModel` are in the same file since they both depend on the `get_last_dagrun()` function.
   - I placed classes and variables related to fernet in `airflow/models/crypto.py`.
   - I had to fix (i.e. disentangle) several weird imports along the way which broke and didn't make sense. Mostly related to `airflow.models` importing absolutely everything in the Airflow project, and other files depending on the import in `airflow.models` instead of the actual module. Some examples:
   	- `AirflowException` was imported in `airflow/models/__init__.py` and multiple other files imported from `airflow.models` while it's defined in `airflow.exceptions`.
   	- Same for TriggerRule, this was imported in `airflow/models/__init__.py` and multiple other files imported TriggerRule from there. However, it's defined in `airflow.utils.trigger_rule.TriggerRule`, so I removed it from models and corrected those imports.
   	- Same for `airflow.utils.timezone`.
   	- `tests/test_models.py` turned out to import `State` twice, once via `from airflow.models import State as ST` and once via `from airflow.utils.state import State`. I removed the `ST` import.
   	- Some mocks had to be changed because you have to mock from the location where you use the function/var/whatever. For example, in tests/test_models.py:TaskInstanceTest.test_email_alert I had to change `@patch('airflow.models.send_email')` into `@patch('airflow.models.taskinstance.send_email')` because it's now called from there and not airflow.models.
   - The `global _CONTEXT_MANAGER_DAG` gave some trouble because a global cannot be shared over multiple files, which made it impossible to split the BaseOperator and DAG. So, I placed the `_CONTEXT_MANAGER_DAG` in airflow/settings.py, and simply import from there. The added benefit is that `global` isn't even needed! Bye bye global :-) More info: https://stackoverflow.com/a/13034908/3066428
   
   I have 3 questions:
   
   1. Since this PR related to AIRFLOW-3456, AIRFLOW-3460, AIRFLOW-3465, AIRFLOW-3466, AIRFLOW-3470, AIRFLOW-3473 and AIRFLOW-3579, what title should I give the PR? Perhaps we could make a parent JIRA issue and place all these items as subissues. @Fokko any thoughts?
   2. In the previous moves we did not preserve backwards compatibility, i.e. models are not imported in airflow.models, instead you now have to do e.g. `from airflow.models.slamiss import SlaMiss`. Should we fix these and import all not-imported models in `airflow.models` after all? And if so: in this PR or separate PR?
   3. Classes `DAG` and `DagModel` are in the same file since they both depend on the `get_last_dagrun()` function. Any strong opinions on keeping it this way, or moving the `get_last_dagrun()` function elsewhere so we can split `DAG` and `DagModel`?
   
   ---------
   
   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [ ] My PR addresses the following [Airflow Jira](https://issues.apache.org/jira/browse/AIRFLOW/) issues and references them in the PR title. For example, "\[AIRFLOW-XXX\] My Airflow PR"
     - https://issues.apache.org/jira/browse/AIRFLOW-XXX
     - In case you are fixing a typo in the documentation you can prepend your commit with \[AIRFLOW-XXX\], code changes always need a Jira issue.
     - In case you are proposing a fundamental code change, you need to create an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)).
     - In case you are adding a dependency, check if the license complies with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   
   ### Description
   
   - [x] Here are some details about my PR, including screenshots of any UI changes:
   
   See above.
   
   ### Tests
   
   - [x] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason:
   
   No new tests, only split tests/test_models.py into modules corresponding to airflow.models.
   
   ### Commits
   
   - [x] My commits all reference Jira issues in their subject lines, and I have squashed multiple commits if they address the same issue. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [x] In case of new functionality, my PR adds documentation that describes how to use it.
     - All the public functions and the classes in the PR contain docstrings that explain what it does
     - If you implement backwards incompatible changes, please leave a note in the [Updating.md](https://github.com/apache/airflow/blob/master/UPDATING.md) so we can assign it to a appropriate release
   
   ### Code Quality
   
   - [x] Passes `flake8`
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services