You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Lee-W (via GitHub)" <gi...@apache.org> on 2024/11/11 09:48:36 UTC
[PR] fix(scheduler_job_runner/asset): fix how asset dag warnning is added [airflow]
Lee-W opened a new pull request, #43873:
URL: https://github.com/apache/airflow/pull/43873
the correct logic is
1. finding the warning that should exist after this round
2. delete the warnings that no longer needed
3. update the warnings if already exist and add new warnings if not yet exists
<!--
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.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
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](https://github.com/apache/airflow/tree/main/newsfragments).
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(scheduler_job_runner/asset): fix how asset dag warning is added [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #43873:
URL: https://github.com/apache/airflow/pull/43873#discussion_r1837821960
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -2113,44 +2114,58 @@ def _activate_referenced_assets(assets: Collection[AssetModel], *, session: Sess
active_name_to_uri: dict[str, str] = {name: uri for name, uri in active_assets}
active_uri_to_name: dict[str, str] = {uri: name for name, uri in active_assets}
- def _generate_dag_warnings(offending: AssetModel, attr: str, value: str) -> Iterator[DagWarning]:
+ def _generate_warning_message(
+ offending: AssetModel, attr: str, value: str
+ ) -> Iterator[tuple[str, str]]:
for ref in itertools.chain(offending.consuming_dags, offending.producing_tasks):
- yield DagWarning(
- dag_id=ref.dag_id,
- error_type=DagWarningType.ASSET_CONFLICT,
- message=f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
+ yield (
+ ref.dag_id,
+ f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
)
- def _activate_assets_generate_warnings() -> Iterator[DagWarning]:
+ def _activate_assets_generate_warnings() -> Iterator[tuple[str, str]]:
incoming_name_to_uri: dict[str, str] = {}
incoming_uri_to_name: dict[str, str] = {}
for asset in assets:
if (asset.name, asset.uri) in active_assets:
continue
existing_uri = active_name_to_uri.get(asset.name) or incoming_name_to_uri.get(asset.name)
if existing_uri is not None and existing_uri != asset.uri:
- yield from _generate_dag_warnings(asset, "name", existing_uri)
+ yield from _generate_warning_message(asset, "name", existing_uri)
continue
existing_name = active_uri_to_name.get(asset.uri) or incoming_uri_to_name.get(asset.uri)
if existing_name is not None and existing_name != asset.name:
- yield from _generate_dag_warnings(asset, "uri", existing_name)
+ yield from _generate_warning_message(asset, "uri", existing_name)
continue
incoming_name_to_uri[asset.name] = asset.uri
incoming_uri_to_name[asset.uri] = asset.name
session.add(AssetActive.for_asset(asset))
- warnings_to_have = {w.dag_id: w for w in _activate_assets_generate_warnings()}
+ def _get_first_item(x: Sequence[Any]) -> Any:
+ return x[0]
+
+ warnings_to_have = {
+ dag_id: DagWarning(
+ dag_id=dag_id,
+ error_type=DagWarningType.ASSET_CONFLICT,
+ message="\n".join([row[1] for row in group]),
+ )
Review Comment:
updated. Thanks!
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -2113,44 +2114,58 @@ def _activate_referenced_assets(assets: Collection[AssetModel], *, session: Sess
active_name_to_uri: dict[str, str] = {name: uri for name, uri in active_assets}
active_uri_to_name: dict[str, str] = {uri: name for name, uri in active_assets}
- def _generate_dag_warnings(offending: AssetModel, attr: str, value: str) -> Iterator[DagWarning]:
+ def _generate_warning_message(
+ offending: AssetModel, attr: str, value: str
+ ) -> Iterator[tuple[str, str]]:
for ref in itertools.chain(offending.consuming_dags, offending.producing_tasks):
- yield DagWarning(
- dag_id=ref.dag_id,
- error_type=DagWarningType.ASSET_CONFLICT,
- message=f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
+ yield (
+ ref.dag_id,
+ f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
)
- def _activate_assets_generate_warnings() -> Iterator[DagWarning]:
+ def _activate_assets_generate_warnings() -> Iterator[tuple[str, str]]:
incoming_name_to_uri: dict[str, str] = {}
incoming_uri_to_name: dict[str, str] = {}
for asset in assets:
if (asset.name, asset.uri) in active_assets:
continue
existing_uri = active_name_to_uri.get(asset.name) or incoming_name_to_uri.get(asset.name)
if existing_uri is not None and existing_uri != asset.uri:
- yield from _generate_dag_warnings(asset, "name", existing_uri)
+ yield from _generate_warning_message(asset, "name", existing_uri)
continue
existing_name = active_uri_to_name.get(asset.uri) or incoming_uri_to_name.get(asset.uri)
if existing_name is not None and existing_name != asset.name:
- yield from _generate_dag_warnings(asset, "uri", existing_name)
+ yield from _generate_warning_message(asset, "uri", existing_name)
continue
incoming_name_to_uri[asset.name] = asset.uri
incoming_uri_to_name[asset.uri] = asset.name
session.add(AssetActive.for_asset(asset))
- warnings_to_have = {w.dag_id: w for w in _activate_assets_generate_warnings()}
+ def _get_first_item(x: Sequence[Any]) -> Any:
+ return x[0]
+
+ warnings_to_have = {
+ dag_id: DagWarning(
+ dag_id=dag_id,
+ error_type=DagWarningType.ASSET_CONFLICT,
+ message="\n".join([row[1] for row in group]),
+ )
+ for dag_id, group in groupby(
+ sorted(_activate_assets_generate_warnings(), key=_get_first_item), key=_get_first_item
Review Comment:
updated. Thanks!
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -2113,44 +2114,58 @@ def _activate_referenced_assets(assets: Collection[AssetModel], *, session: Sess
active_name_to_uri: dict[str, str] = {name: uri for name, uri in active_assets}
active_uri_to_name: dict[str, str] = {uri: name for name, uri in active_assets}
- def _generate_dag_warnings(offending: AssetModel, attr: str, value: str) -> Iterator[DagWarning]:
+ def _generate_warning_message(
+ offending: AssetModel, attr: str, value: str
+ ) -> Iterator[tuple[str, str]]:
for ref in itertools.chain(offending.consuming_dags, offending.producing_tasks):
- yield DagWarning(
- dag_id=ref.dag_id,
- error_type=DagWarningType.ASSET_CONFLICT,
- message=f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
+ yield (
+ ref.dag_id,
+ f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
)
- def _activate_assets_generate_warnings() -> Iterator[DagWarning]:
+ def _activate_assets_generate_warnings() -> Iterator[tuple[str, str]]:
incoming_name_to_uri: dict[str, str] = {}
incoming_uri_to_name: dict[str, str] = {}
for asset in assets:
if (asset.name, asset.uri) in active_assets:
continue
existing_uri = active_name_to_uri.get(asset.name) or incoming_name_to_uri.get(asset.name)
if existing_uri is not None and existing_uri != asset.uri:
- yield from _generate_dag_warnings(asset, "name", existing_uri)
+ yield from _generate_warning_message(asset, "name", existing_uri)
continue
existing_name = active_uri_to_name.get(asset.uri) or incoming_uri_to_name.get(asset.uri)
if existing_name is not None and existing_name != asset.name:
- yield from _generate_dag_warnings(asset, "uri", existing_name)
+ yield from _generate_warning_message(asset, "uri", existing_name)
continue
incoming_name_to_uri[asset.name] = asset.uri
incoming_uri_to_name[asset.uri] = asset.name
session.add(AssetActive.for_asset(asset))
- warnings_to_have = {w.dag_id: w for w in _activate_assets_generate_warnings()}
+ def _get_first_item(x: Sequence[Any]) -> Any:
+ return x[0]
Review Comment:
updated. Thanks!
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(scheduler_job_runner/asset): fix how asset dag warning is added [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #43873:
URL: https://github.com/apache/airflow/pull/43873#discussion_r1837804087
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -2113,44 +2114,58 @@ def _activate_referenced_assets(assets: Collection[AssetModel], *, session: Sess
active_name_to_uri: dict[str, str] = {name: uri for name, uri in active_assets}
active_uri_to_name: dict[str, str] = {uri: name for name, uri in active_assets}
- def _generate_dag_warnings(offending: AssetModel, attr: str, value: str) -> Iterator[DagWarning]:
+ def _generate_warning_message(
+ offending: AssetModel, attr: str, value: str
+ ) -> Iterator[tuple[str, str]]:
for ref in itertools.chain(offending.consuming_dags, offending.producing_tasks):
- yield DagWarning(
- dag_id=ref.dag_id,
- error_type=DagWarningType.ASSET_CONFLICT,
- message=f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
+ yield (
+ ref.dag_id,
+ f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
)
- def _activate_assets_generate_warnings() -> Iterator[DagWarning]:
+ def _activate_assets_generate_warnings() -> Iterator[tuple[str, str]]:
incoming_name_to_uri: dict[str, str] = {}
incoming_uri_to_name: dict[str, str] = {}
for asset in assets:
if (asset.name, asset.uri) in active_assets:
continue
existing_uri = active_name_to_uri.get(asset.name) or incoming_name_to_uri.get(asset.name)
if existing_uri is not None and existing_uri != asset.uri:
- yield from _generate_dag_warnings(asset, "name", existing_uri)
+ yield from _generate_warning_message(asset, "name", existing_uri)
continue
existing_name = active_uri_to_name.get(asset.uri) or incoming_uri_to_name.get(asset.uri)
if existing_name is not None and existing_name != asset.name:
- yield from _generate_dag_warnings(asset, "uri", existing_name)
+ yield from _generate_warning_message(asset, "uri", existing_name)
continue
incoming_name_to_uri[asset.name] = asset.uri
incoming_uri_to_name[asset.uri] = asset.name
session.add(AssetActive.for_asset(asset))
- warnings_to_have = {w.dag_id: w for w in _activate_assets_generate_warnings()}
+ def _get_first_item(x: Sequence[Any]) -> Any:
+ return x[0]
+
+ warnings_to_have = {
Review Comment:
Do you mean we should reduce the warnings from 3 to 1?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(scheduler_job_runner/asset): fix how asset dag warning is added [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W merged PR #43873:
URL: https://github.com/apache/airflow/pull/43873
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(scheduler_job_runner/asset): fix how asset dag warning is added [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #43873:
URL: https://github.com/apache/airflow/pull/43873#discussion_r1837805314
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -2113,44 +2114,58 @@ def _activate_referenced_assets(assets: Collection[AssetModel], *, session: Sess
active_name_to_uri: dict[str, str] = {name: uri for name, uri in active_assets}
active_uri_to_name: dict[str, str] = {uri: name for name, uri in active_assets}
- def _generate_dag_warnings(offending: AssetModel, attr: str, value: str) -> Iterator[DagWarning]:
+ def _generate_warning_message(
+ offending: AssetModel, attr: str, value: str
+ ) -> Iterator[tuple[str, str]]:
for ref in itertools.chain(offending.consuming_dags, offending.producing_tasks):
- yield DagWarning(
- dag_id=ref.dag_id,
- error_type=DagWarningType.ASSET_CONFLICT,
- message=f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
+ yield (
+ ref.dag_id,
+ f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
)
- def _activate_assets_generate_warnings() -> Iterator[DagWarning]:
+ def _activate_assets_generate_warnings() -> Iterator[tuple[str, str]]:
incoming_name_to_uri: dict[str, str] = {}
incoming_uri_to_name: dict[str, str] = {}
for asset in assets:
if (asset.name, asset.uri) in active_assets:
continue
existing_uri = active_name_to_uri.get(asset.name) or incoming_name_to_uri.get(asset.name)
if existing_uri is not None and existing_uri != asset.uri:
- yield from _generate_dag_warnings(asset, "name", existing_uri)
+ yield from _generate_warning_message(asset, "name", existing_uri)
continue
existing_name = active_uri_to_name.get(asset.uri) or incoming_uri_to_name.get(asset.uri)
if existing_name is not None and existing_name != asset.name:
- yield from _generate_dag_warnings(asset, "uri", existing_name)
+ yield from _generate_warning_message(asset, "uri", existing_name)
continue
incoming_name_to_uri[asset.name] = asset.uri
incoming_uri_to_name[asset.uri] = asset.name
session.add(AssetActive.for_asset(asset))
- warnings_to_have = {w.dag_id: w for w in _activate_assets_generate_warnings()}
+ def _get_first_item(x: Sequence[Any]) -> Any:
+ return x[0]
+
+ warnings_to_have = {
+ dag_id: DagWarning(
+ dag_id=dag_id,
+ error_type=DagWarningType.ASSET_CONFLICT,
+ message="\n".join([row[1] for row in group]),
+ )
Review Comment:
```suggestion
dag_id: DagWarning(
dag_id=dag_id,
error_type=DagWarningType.ASSET_CONFLICT,
message="\n".join(message for _, message in group]),
)
```
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(scheduler_job_runner/asset): fix how asset dag warning is added [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #43873:
URL: https://github.com/apache/airflow/pull/43873#discussion_r1837815184
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -2113,44 +2114,58 @@ def _activate_referenced_assets(assets: Collection[AssetModel], *, session: Sess
active_name_to_uri: dict[str, str] = {name: uri for name, uri in active_assets}
active_uri_to_name: dict[str, str] = {uri: name for name, uri in active_assets}
- def _generate_dag_warnings(offending: AssetModel, attr: str, value: str) -> Iterator[DagWarning]:
+ def _generate_warning_message(
+ offending: AssetModel, attr: str, value: str
+ ) -> Iterator[tuple[str, str]]:
for ref in itertools.chain(offending.consuming_dags, offending.producing_tasks):
- yield DagWarning(
- dag_id=ref.dag_id,
- error_type=DagWarningType.ASSET_CONFLICT,
- message=f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
+ yield (
+ ref.dag_id,
+ f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
)
- def _activate_assets_generate_warnings() -> Iterator[DagWarning]:
+ def _activate_assets_generate_warnings() -> Iterator[tuple[str, str]]:
incoming_name_to_uri: dict[str, str] = {}
incoming_uri_to_name: dict[str, str] = {}
for asset in assets:
if (asset.name, asset.uri) in active_assets:
continue
existing_uri = active_name_to_uri.get(asset.name) or incoming_name_to_uri.get(asset.name)
if existing_uri is not None and existing_uri != asset.uri:
- yield from _generate_dag_warnings(asset, "name", existing_uri)
+ yield from _generate_warning_message(asset, "name", existing_uri)
continue
existing_name = active_uri_to_name.get(asset.uri) or incoming_uri_to_name.get(asset.uri)
if existing_name is not None and existing_name != asset.name:
- yield from _generate_dag_warnings(asset, "uri", existing_name)
+ yield from _generate_warning_message(asset, "uri", existing_name)
continue
incoming_name_to_uri[asset.name] = asset.uri
incoming_uri_to_name[asset.uri] = asset.name
session.add(AssetActive.for_asset(asset))
- warnings_to_have = {w.dag_id: w for w in _activate_assets_generate_warnings()}
+ def _get_first_item(x: Sequence[Any]) -> Any:
+ return x[0]
+
+ warnings_to_have = {
Review Comment:
In the existing logic, we only raise the latest one (if I'm not mistaken). In this implementation, the error will look like "Cannot activate asset Asset(...); ... is already associated to ...\nCannot activate asset Asset(...); ... is already associated to ...".
I don't think we can add multiple DagWarning unless we want to remove the unique constriant 🤔
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(scheduler_job_runner/asset): fix how asset dag warning is added [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #43873:
URL: https://github.com/apache/airflow/pull/43873#discussion_r1836483362
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -2113,44 +2114,58 @@ def _activate_referenced_assets(assets: Collection[AssetModel], *, session: Sess
active_name_to_uri: dict[str, str] = {name: uri for name, uri in active_assets}
active_uri_to_name: dict[str, str] = {uri: name for name, uri in active_assets}
- def _generate_dag_warnings(offending: AssetModel, attr: str, value: str) -> Iterator[DagWarning]:
+ def _generate_warning_message(
+ offending: AssetModel, attr: str, value: str
+ ) -> Iterator[tuple[str, str]]:
for ref in itertools.chain(offending.consuming_dags, offending.producing_tasks):
- yield DagWarning(
- dag_id=ref.dag_id,
- error_type=DagWarningType.ASSET_CONFLICT,
- message=f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
+ yield (
+ ref.dag_id,
+ f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
)
- def _activate_assets_generate_warnings() -> Iterator[DagWarning]:
+ def _activate_assets_generate_warnings() -> Iterator[tuple[str, str]]:
incoming_name_to_uri: dict[str, str] = {}
incoming_uri_to_name: dict[str, str] = {}
for asset in assets:
if (asset.name, asset.uri) in active_assets:
continue
existing_uri = active_name_to_uri.get(asset.name) or incoming_name_to_uri.get(asset.name)
if existing_uri is not None and existing_uri != asset.uri:
- yield from _generate_dag_warnings(asset, "name", existing_uri)
+ yield from _generate_warning_message(asset, "name", existing_uri)
continue
existing_name = active_uri_to_name.get(asset.uri) or incoming_uri_to_name.get(asset.uri)
if existing_name is not None and existing_name != asset.name:
- yield from _generate_dag_warnings(asset, "uri", existing_name)
+ yield from _generate_warning_message(asset, "uri", existing_name)
continue
incoming_name_to_uri[asset.name] = asset.uri
incoming_uri_to_name[asset.uri] = asset.name
session.add(AssetActive.for_asset(asset))
- warnings_to_have = {w.dag_id: w for w in _activate_assets_generate_warnings()}
+ def _get_first_item(x: Sequence[Any]) -> Any:
+ return x[0]
+
+ warnings_to_have = {
Review Comment:
@uranusjr, I'm not sure whether we want to warn a case like this 🤔 It kinda makes the logic a bit more complicated. The message is just concatenated.
```python
schedule=(
Asset(name="asset1_producer", uri="s3://bucket/asset1_producer1")
| Asset(name="asset1_producer", uri="s3://bucket/asset1_producer2")
| Asset(name="asset1_producer", uri="s3://bucket/asset1_producer3")
| Asset(name="asset1_producer", uri="s3://bucket/asset1_producer4")
),
```
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(scheduler_job_runner/asset): fix how asset dag warning is added [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #43873:
URL: https://github.com/apache/airflow/pull/43873#discussion_r1837801397
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -2113,44 +2114,58 @@ def _activate_referenced_assets(assets: Collection[AssetModel], *, session: Sess
active_name_to_uri: dict[str, str] = {name: uri for name, uri in active_assets}
active_uri_to_name: dict[str, str] = {uri: name for name, uri in active_assets}
- def _generate_dag_warnings(offending: AssetModel, attr: str, value: str) -> Iterator[DagWarning]:
+ def _generate_warning_message(
+ offending: AssetModel, attr: str, value: str
+ ) -> Iterator[tuple[str, str]]:
for ref in itertools.chain(offending.consuming_dags, offending.producing_tasks):
- yield DagWarning(
- dag_id=ref.dag_id,
- error_type=DagWarningType.ASSET_CONFLICT,
- message=f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
+ yield (
+ ref.dag_id,
+ f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
)
- def _activate_assets_generate_warnings() -> Iterator[DagWarning]:
+ def _activate_assets_generate_warnings() -> Iterator[tuple[str, str]]:
incoming_name_to_uri: dict[str, str] = {}
incoming_uri_to_name: dict[str, str] = {}
for asset in assets:
if (asset.name, asset.uri) in active_assets:
continue
existing_uri = active_name_to_uri.get(asset.name) or incoming_name_to_uri.get(asset.name)
if existing_uri is not None and existing_uri != asset.uri:
- yield from _generate_dag_warnings(asset, "name", existing_uri)
+ yield from _generate_warning_message(asset, "name", existing_uri)
continue
existing_name = active_uri_to_name.get(asset.uri) or incoming_uri_to_name.get(asset.uri)
if existing_name is not None and existing_name != asset.name:
- yield from _generate_dag_warnings(asset, "uri", existing_name)
+ yield from _generate_warning_message(asset, "uri", existing_name)
continue
incoming_name_to_uri[asset.name] = asset.uri
incoming_uri_to_name[asset.uri] = asset.name
session.add(AssetActive.for_asset(asset))
- warnings_to_have = {w.dag_id: w for w in _activate_assets_generate_warnings()}
+ def _get_first_item(x: Sequence[Any]) -> Any:
+ return x[0]
Review Comment:
There’s a built-in solution, `operator.itemgetter(0)`
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(scheduler_job_runner/asset): fix how asset dag warning is added [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #43873:
URL: https://github.com/apache/airflow/pull/43873#discussion_r1837811738
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -2113,44 +2114,58 @@ def _activate_referenced_assets(assets: Collection[AssetModel], *, session: Sess
active_name_to_uri: dict[str, str] = {name: uri for name, uri in active_assets}
active_uri_to_name: dict[str, str] = {uri: name for name, uri in active_assets}
- def _generate_dag_warnings(offending: AssetModel, attr: str, value: str) -> Iterator[DagWarning]:
+ def _generate_warning_message(
+ offending: AssetModel, attr: str, value: str
+ ) -> Iterator[tuple[str, str]]:
for ref in itertools.chain(offending.consuming_dags, offending.producing_tasks):
- yield DagWarning(
- dag_id=ref.dag_id,
- error_type=DagWarningType.ASSET_CONFLICT,
- message=f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
+ yield (
+ ref.dag_id,
+ f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
)
- def _activate_assets_generate_warnings() -> Iterator[DagWarning]:
+ def _activate_assets_generate_warnings() -> Iterator[tuple[str, str]]:
incoming_name_to_uri: dict[str, str] = {}
incoming_uri_to_name: dict[str, str] = {}
for asset in assets:
if (asset.name, asset.uri) in active_assets:
continue
existing_uri = active_name_to_uri.get(asset.name) or incoming_name_to_uri.get(asset.name)
if existing_uri is not None and existing_uri != asset.uri:
- yield from _generate_dag_warnings(asset, "name", existing_uri)
+ yield from _generate_warning_message(asset, "name", existing_uri)
continue
existing_name = active_uri_to_name.get(asset.uri) or incoming_uri_to_name.get(asset.uri)
if existing_name is not None and existing_name != asset.name:
- yield from _generate_dag_warnings(asset, "uri", existing_name)
+ yield from _generate_warning_message(asset, "uri", existing_name)
continue
incoming_name_to_uri[asset.name] = asset.uri
incoming_uri_to_name[asset.uri] = asset.name
session.add(AssetActive.for_asset(asset))
- warnings_to_have = {w.dag_id: w for w in _activate_assets_generate_warnings()}
+ def _get_first_item(x: Sequence[Any]) -> Any:
+ return x[0]
+
+ warnings_to_have = {
+ dag_id: DagWarning(
+ dag_id=dag_id,
+ error_type=DagWarningType.ASSET_CONFLICT,
+ message="\n".join([row[1] for row in group]),
+ )
+ for dag_id, group in groupby(
+ sorted(_activate_assets_generate_warnings(), key=_get_first_item), key=_get_first_item
Review Comment:
yep, you're right, we don't need to do it here. but I think `groupby` still need it?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(scheduler_job_runner/asset): fix how asset dag warning is added [airflow]
Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr commented on code in PR #43873:
URL: https://github.com/apache/airflow/pull/43873#discussion_r1837806826
##########
airflow/jobs/scheduler_job_runner.py:
##########
@@ -2113,44 +2114,58 @@ def _activate_referenced_assets(assets: Collection[AssetModel], *, session: Sess
active_name_to_uri: dict[str, str] = {name: uri for name, uri in active_assets}
active_uri_to_name: dict[str, str] = {uri: name for name, uri in active_assets}
- def _generate_dag_warnings(offending: AssetModel, attr: str, value: str) -> Iterator[DagWarning]:
+ def _generate_warning_message(
+ offending: AssetModel, attr: str, value: str
+ ) -> Iterator[tuple[str, str]]:
for ref in itertools.chain(offending.consuming_dags, offending.producing_tasks):
- yield DagWarning(
- dag_id=ref.dag_id,
- error_type=DagWarningType.ASSET_CONFLICT,
- message=f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
+ yield (
+ ref.dag_id,
+ f"Cannot activate asset {offending}; {attr} is already associated to {value!r}",
)
- def _activate_assets_generate_warnings() -> Iterator[DagWarning]:
+ def _activate_assets_generate_warnings() -> Iterator[tuple[str, str]]:
incoming_name_to_uri: dict[str, str] = {}
incoming_uri_to_name: dict[str, str] = {}
for asset in assets:
if (asset.name, asset.uri) in active_assets:
continue
existing_uri = active_name_to_uri.get(asset.name) or incoming_name_to_uri.get(asset.name)
if existing_uri is not None and existing_uri != asset.uri:
- yield from _generate_dag_warnings(asset, "name", existing_uri)
+ yield from _generate_warning_message(asset, "name", existing_uri)
continue
existing_name = active_uri_to_name.get(asset.uri) or incoming_uri_to_name.get(asset.uri)
if existing_name is not None and existing_name != asset.name:
- yield from _generate_dag_warnings(asset, "uri", existing_name)
+ yield from _generate_warning_message(asset, "uri", existing_name)
continue
incoming_name_to_uri[asset.name] = asset.uri
incoming_uri_to_name[asset.uri] = asset.name
session.add(AssetActive.for_asset(asset))
- warnings_to_have = {w.dag_id: w for w in _activate_assets_generate_warnings()}
+ def _get_first_item(x: Sequence[Any]) -> Any:
+ return x[0]
+
+ warnings_to_have = {
+ dag_id: DagWarning(
+ dag_id=dag_id,
+ error_type=DagWarningType.ASSET_CONFLICT,
+ message="\n".join([row[1] for row in group]),
+ )
+ for dag_id, group in groupby(
+ sorted(_activate_assets_generate_warnings(), key=_get_first_item), key=_get_first_item
Review Comment:
Actually I don’t think we even need to specify `key` here; tuple is naturally ordered by its first item anyway.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org