-
Notifications
You must be signed in to change notification settings - Fork 14.4k
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
[AIRFLOW-3561] Improve queries #4368
Conversation
Codecov Report
@@ Coverage Diff @@
## master #4368 +/- ##
==========================================
+ Coverage 78.14% 78.17% +0.02%
==========================================
Files 202 204 +2
Lines 16486 16530 +44
==========================================
+ Hits 12883 12922 +39
- Misses 3603 3608 +5
Continue to review full report at Codecov.
|
airflow/models/__init__.py
Outdated
return self._default_view | ||
|
||
def get_default_view(self): | ||
"""This is only there for backward compatible jina2 templates""" |
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.
I think I'm missing something here. Why can't the templates continue using the default_view
property? Also, s/jina2/jinja2/.
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.
This was to do with https://issues.apache.org/jira/browse/AIRFLOW-3562.
Currently DAG is still used in other templates, can't change all those at once. Once all views has switched to DagModel this method can be removed again.
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.
ps: fixing typo ;)
@@ -4201,6 +4222,8 @@ def sync_to_db(self, owner=None, sync_time=None, session=None): | |||
orm_dag.owners = owner | |||
orm_dag.is_active = True | |||
orm_dag.last_scheduler_run = sync_time | |||
orm_dag.default_view = self._default_view |
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.
Can we test this in tests.models:DagTest.test_sync_to_db
?
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.
Good one, added a test
airflow/models/__init__.py
Outdated
@@ -3249,6 +3259,17 @@ def __exit__(self, _type, _value, _tb): | |||
|
|||
# /Context Manager ---------------------------------------------- | |||
|
|||
@property | |||
def default_view(self): |
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.
Can we test this property?
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.
Good one, added a test
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.
This behavior how differs from the get_default_view
method. Maybe we can remove the get_default_view
method completely: https://stackoverflow.com/questions/49134141/how-do-i-reference-an-object-property-in-a-method-call-in-jinja2
This would reduce the number of methods on the DAG object. Besides that, I believe that dag.default_view
should return the same as dag.get_default_view()
since the names are so similar.
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.
@Fokko Agree there. I did now remove all usage of dag.default_view and switch it to dag.get_default_view()
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.
@Fokko: Can't use just default_view
because in DagModel this can be None and get_default_view has a fall back to the config when not set.
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.
Awesome, thanks!
Until #4339 is merged, we have to make duplicate changes to |
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.
Small suggestions, apart from that it looks great!
airflow/models/__init__.py
Outdated
@@ -3249,6 +3259,17 @@ def __exit__(self, _type, _value, _tb): | |||
|
|||
# /Context Manager ---------------------------------------------- | |||
|
|||
@property | |||
def default_view(self): |
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.
This behavior how differs from the get_default_view
method. Maybe we can remove the get_default_view
method completely: https://stackoverflow.com/questions/49134141/how-do-i-reference-an-object-property-in-a-method-call-in-jinja2
This would reduce the number of methods on the DAG object. Besides that, I believe that dag.default_view
should return the same as dag.get_default_view()
since the names are so similar.
qry = ( | ||
session.query(ds.dag_id, ds.state, ds.count) | ||
) | ||
states = session.query(dr.dag_id, dr.state, sqla.func.count(dr.state)).group_by(dr.dag_id, dr.state) | ||
|
||
data = {} |
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.
Maybe give this a bit more meaningful name? Something like dag_state_stats
.
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.
👍
Two related CI issues:
|
Rbac is now also fixed |
* improve queries * Adding field to the database * Set length of field * remove dagbag use in xcom call * Fixing typo * Adding test * Remove default_view * fixing test * rename var * Fixing rbac dag_stats * Fixing rbac task_stats * Fixing rbac code * Fixing rbac xcom * Fixing template * Fixing default view call * Added timezone to DagModel * Fixing timezone
|
||
def __repr__(self): | ||
return "<DAG: {self.dag_id}>".format(self=self) | ||
|
||
@property | ||
def timezone(self): | ||
return settings.TIMEZONE |
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.
Wait up - this looks incorrect. Why was this removed?
The timezone of a DAG was previously defined as the timezone of the start_date. Is that still the case and if we do self.timezone = tz
then this property accessor won't be used anymore?
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.
I don't mean removed, I mean added.
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.
Oh this is on the DagModel, not the DAG. Right.
In which case my question is: when/where is this used?
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.
This is indeed a bit tricky. I have added this because in the html templates this variable is used. Some templates now takes a DagModel instead of a DAG. In the end I would like this to be in the complete webserver
* improve queries * Adding field to the database * Set length of field * remove dagbag use in xcom call * Fixing typo * Adding test * Remove default_view * fixing test * rename var * Fixing rbac dag_stats * Fixing rbac task_stats * Fixing rbac code * Fixing rbac xcom * Fixing template * Fixing default view call * Added timezone to DagModel * Fixing timezone
We reverted this from master? Did it ever make it back in in any form? |
@ashb Seems to be still in there: Because of the switch to the rbac interface it's was moved I think |
* improve queries * Adding field to the database * Set length of field * remove dagbag use in xcom call * Fixing typo * Adding test * Remove default_view * fixing test * rename var * Fixing rbac dag_stats * Fixing rbac task_stats * Fixing rbac code * Fixing rbac xcom * Fixing template * Fixing default view call * Added timezone to DagModel * Fixing timezone
apache#5111) We used to key on `safe_dag_id` but in that got changed in apache#4368 to use a more efficient query, which broke for non-sub-DAGs that contain a `.` in their id. Arguably this escaping is a front-end concern anyway, so handling the escaping in the front end makes sense anyway. (cherry picked from commit c696dd4)
apache#5111) We used to key on `safe_dag_id` but in that got changed in apache#4368 to use a more efficient query, which broke for non-sub-DAGs that contain a `.` in their id. Arguably this escaping is a front-end concern anyway, so handling the escaping in the front end makes sense anyway.
apache#5111) We used to key on `safe_dag_id` but in that got changed in apache#4368 to use a more efficient query, which broke for non-sub-DAGs that contain a `.` in their id. Arguably this escaping is a front-end concern anyway, so handling the escaping in the front end makes sense anyway. (cherry picked from commit c696dd4)
apache#5111) We used to key on `safe_dag_id` but in that got changed in apache#4368 to use a more efficient query, which broke for non-sub-DAGs that contain a `.` in their id. Arguably this escaping is a front-end concern anyway, so handling the escaping in the front end makes sense anyway.
* improve queries * Adding field to the database * Set length of field * remove dagbag use in xcom call * Fixing typo * Adding test * Remove default_view * fixing test * rename var * Fixing rbac dag_stats * Fixing rbac task_stats * Fixing rbac code * Fixing rbac xcom * Fixing template * Fixing default view call * Added timezone to DagModel * Fixing timezone
apache#5111) We used to key on `safe_dag_id` but in that got changed in apache#4368 to use a more efficient query, which broke for non-sub-DAGs that contain a `.` in their id. Arguably this escaping is a front-end concern anyway, so handling the escaping in the front end makes sense anyway.
apache#5111) We used to key on `safe_dag_id` but in that got changed in apache#4368 to use a more efficient query, which broke for non-sub-DAGs that contain a `.` in their id. Arguably this escaping is a front-end concern anyway, so handling the escaping in the front end makes sense anyway.
apache#5111) We used to key on `safe_dag_id` but in that got changed in apache#4368 to use a more efficient query, which broke for non-sub-DAGs that contain a `.` in their id. Arguably this escaping is a front-end concern anyway, so handling the escaping in the front end makes sense anyway.
Make sure you have checked all steps below.
Jira
Description
This pull request will reduce interaction with the DagBag en improves database queries.
Tests
Commits
Documentation
Code Quality
flake8