You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "uranusjr (via GitHub)" <gi...@apache.org> on 2024/12/18 12:03:58 UTC

[PR] Implement Asset.ref for name or URI references [airflow]

uranusjr opened a new pull request, #45028:
URL: https://github.com/apache/airflow/pull/45028

   This allows us to refer to an asset without needing the original object, making it easier to schedule against an asset.
   
   I also added some minor improvements to `register_asset_change` so we can save a db query or the asset-model conversion in some cases.
   
   There are a couple of possible sytax designs available:
   
   ```python
   # Magic constructor.
   AssetRef(name="asset-1")
   AssetRef(uri="s3://bucket/assets/1")
   
   # Magic factory method on Asset.
   Asset.ref(name="asset-1")
   Asset.ref(uri="s3://bucket/assets/1")
   ```
   
   I’m opting for the second one with a factory method since it is easier to implement, but we can discuss which one we like better.


-- 
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] Implement Asset.ref for name or URI references [airflow]

Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #45028:
URL: https://github.com/apache/airflow/pull/45028#discussion_r1897131854


##########
airflow/models/asset.py:
##########
@@ -68,6 +80,22 @@ def expand_alias_to_assets(alias_name: str, session: Session) -> Iterable[AssetM
     return []
 
 
+def resolve_ref_to_asset(
+    *,
+    name: str | None = None,
+    uri: str | None = None,
+    session: Session,
+) -> AssetModel | None:
+    if name is None and uri is None:
+        raise TypeError("either name or uri is required")
+    stmt = select(AssetModel).where(AssetModel.active.has())
+    if name is not None:
+        stmt = stmt.where(AssetModel.name == name)
+    if uri is not None:
+        stmt = stmt.where(AssetModel.uri == uri)

Review Comment:
   Even though in the current design, it's not possible that both `name` and `uri` are not None, should we catch the case that both of them have value? If it's changed in the future and we forget to change the function here, it might be a bit counterintuitive to debug as the stmt just slightly assigned twice



##########
airflow/models/asset.py:
##########
@@ -68,6 +80,22 @@ def expand_alias_to_assets(alias_name: str, session: Session) -> Iterable[AssetM
     return []
 
 
+def resolve_ref_to_asset(
+    *,
+    name: str | None = None,
+    uri: str | None = None,
+    session: Session,
+) -> AssetModel | None:
+    if name is None and uri is None:
+        raise TypeError("either name or uri is required")

Review Comment:
   Not sure if `TypeError` fits the best šŸ¤” 



##########
airflow/models/asset.py:
##########
@@ -68,6 +80,22 @@ def expand_alias_to_assets(alias_name: str, session: Session) -> Iterable[AssetM
     return []
 
 
+def resolve_ref_to_asset(
+    *,
+    name: str | None = None,
+    uri: str | None = None,
+    session: Session,
+) -> AssetModel | None:
+    if name is None and uri is None:
+        raise TypeError("either name or uri is required")

Review Comment:
   Not sure if `TypeError` fits the best šŸ¤” 



-- 
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] Implement Asset.ref for name or URI references [airflow]

Posted by "uranusjr (via GitHub)" <gi...@apache.org>.
uranusjr merged PR #45028:
URL: https://github.com/apache/airflow/pull/45028


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