This is an automated email from the ASF dual-hosted git repository.
kaxil pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new 6a89cc719d6 Make embedding external files opt-in for Hugging Face Hub
publications (#77646)
6a89cc719d6 is described below
commit 6a89cc719d6b3382f5ee834efec36f6463676550
Author: Kaxil Naik <[email protected]>
AuthorDate: Sat Nov 28 00:43:40 2026 +0000
Make embedding external files opt-in for Hugging Face Hub publications
(#77646)
StreamDatasetOperator copies a pinned Hub dataset revision by handing the
stream to Datasets' push_to_hub. That method's embed_external_files default
reads the files that media rows reference by path and writes their bytes
into the published shards, so the copy depends on what those paths resolve
to at push time and not only on the rows of the pinned revision.
For a Hub source the operator now passes embed_external_files=False unless
push_kwargs sets it, so rows are published as they are stored. Local
sources are not affected. PushToHubOperator passes the same default;
artifacts written by the provider hold no media columns, so nothing
changes for them.
---
providers/huggingface/docs/changelog.rst | 7 +++
providers/huggingface/docs/operators/datasets.rst | 15 ++++++-
.../providers/huggingface/operators/datasets.py | 5 +++
.../unit/huggingface/operators/test_datasets.py | 50 ++++++++++++++++++++++
4 files changed, 76 insertions(+), 1 deletion(-)
diff --git a/providers/huggingface/docs/changelog.rst
b/providers/huggingface/docs/changelog.rst
index d4c2f1e4f48..e4f8c2fcb1e 100644
--- a/providers/huggingface/docs/changelog.rst
+++ b/providers/huggingface/docs/changelog.rst
@@ -27,6 +27,13 @@
Changelog
---------
+.. note::
+ ``StreamDatasetOperator`` now passes ``embed_external_files=False`` to
``push_to_hub`` when the source
+ is a Hub repository. Rows that reference a media file by path are
published with that path, not the
+ file's bytes. With `Hugging Face Datasets
<https://huggingface.co/docs/datasets/>`__ 5.0 and 5.1 this
+ includes a Hub image folder, which those versions stream as file
references; 5.2.0 streams it as
+ bytes. Set ``push_kwargs={"embed_external_files": True}`` to use the
library's default as before.
+
0.1.0
.....
diff --git a/providers/huggingface/docs/operators/datasets.rst
b/providers/huggingface/docs/operators/datasets.rst
index f8e66310e25..13135e5fd6e 100644
--- a/providers/huggingface/docs/operators/datasets.rst
+++ b/providers/huggingface/docs/operators/datasets.rst
@@ -158,6 +158,16 @@ downstream tasks should load the published Hub repository.
Passing
substitute: that operator writes a durable artifact and its writer accepts
``Dataset`` and ``DatasetDict``, not ``IterableDataset``.
+For a Hub source the operator passes ``embed_external_files=False`` to
+``push_to_hub``, so rows are published as they are stored: media bytes held in
+a row of an ``Image``, ``Audio``, or similar column are copied, and a row that
+references a file by path is published with that path, not the file's bytes.
+Readers of the published repository then need access to the referenced file.
+Datasets 5.2.0 streams a Hub image folder as bytes, so it is copied whole;
+5.0 and 5.1 stream it as file references. Set
+``push_kwargs={"embed_external_files": True}`` to use the Datasets default for
+this option. Local sources are not affected.
+
PushToHubOperator
-----------------
@@ -180,7 +190,10 @@ state or Hub-marker reuse. It returns ``repository_id``,
the Hub commit identifi
``commit_sha``, the commit URL as ``commit_url``, the artifact fingerprint,
and source provenance. Both live ``CommitInfo`` and recovered
``GitCommitInfo`` records are supported. Hub exceptions propagate without
-wrapping.
+wrapping. Like ``StreamDatasetOperator``, it passes
+``embed_external_files=False`` to ``push_to_hub`` unless ``push_kwargs`` sets
+it; artifacts written by this provider hold no media columns, so this changes
+nothing for them.
The commit message includes an artifact fingerprint and target marker. The
marker distinguishes repository configuration, revision, pull request target,
diff --git
a/providers/huggingface/src/airflow/providers/huggingface/operators/datasets.py
b/providers/huggingface/src/airflow/providers/huggingface/operators/datasets.py
index 280e2a89384..5284d13d5a8 100644
---
a/providers/huggingface/src/airflow/providers/huggingface/operators/datasets.py
+++
b/providers/huggingface/src/airflow/providers/huggingface/operators/datasets.py
@@ -571,6 +571,9 @@ class StreamDatasetOperator(BaseOperator):
message = self.commit_message or "Stream dataset from Airflow"
push_kwargs["commit_message"] = f"{message} [{marker}]"
+ if is_hub_repo:
+ # Hub rows are published as stored; embedding the files they
reference is opt-in.
+ push_kwargs.setdefault("embed_external_files", False)
if state is not None:
state.set(pending_key, True)
commit = hook.push_to_hub(stream, self.repo_id, **push_kwargs)
@@ -763,6 +766,8 @@ class PushToHubOperator(BaseOperator):
)
message = self.commit_message or "Publish dataset from Airflow"
kwargs["commit_message"] = f"{message} [{marker}]"
+ # Artifact rows are published as stored; embedding the files
they reference is opt-in.
+ kwargs.setdefault("embed_external_files", False)
if state is not None:
state.set(pending_key, True)
commit = hook.push_to_hub(dataset, self.repo_id, **kwargs)
diff --git
a/providers/huggingface/tests/unit/huggingface/operators/test_datasets.py
b/providers/huggingface/tests/unit/huggingface/operators/test_datasets.py
index 5459bd74a1e..33428a33a1b 100644
--- a/providers/huggingface/tests/unit/huggingface/operators/test_datasets.py
+++ b/providers/huggingface/tests/unit/huggingface/operators/test_datasets.py
@@ -203,6 +203,38 @@ def
test_stream_operator_recovers_prior_commit_without_reloading_stream():
assert result["commit_sha"] == commit.oid
[email protected](
+ ("local_source", "push_kwargs", "expected"),
+ [
+ pytest.param(False, {}, False, id="hub-source-default"),
+ pytest.param(False, {"embed_external_files": True}, True,
id="hub-source-opt-in"),
+ pytest.param(True, {}, None, id="local-source-keeps-datasets-default"),
+ ],
+)
+def test_stream_operator_embeds_external_files_of_hub_source_only_on_request(
+ tmp_path, local_source, push_kwargs, expected
+):
+ stream = Dataset.from_dict({"value": [1]}).to_iterable_dataset()
+ with (
+ patch("airflow.providers.huggingface.hooks.huggingface.HfApi",
autospec=True) as hf_api,
+ patch("datasets.load_dataset", autospec=True, return_value=stream),
+ patch(
+ "datasets.IterableDataset.push_to_hub", autospec=True,
return_value=commit_info("org/streamed")
+ ) as push_to_hub,
+ ):
+ hf_api.return_value.dataset_info.return_value.sha = "pinned-stream-sha"
+ StreamDatasetOperator(
+ task_id="stream",
+ path=str(tmp_path) if local_source else "org/source",
+ repo_id="org/streamed",
+ push_kwargs=push_kwargs,
+ huggingface_conn_id=None,
+ durable=False,
+ ).execute({})
+
+ assert push_to_hub.call_args.kwargs.get("embed_external_files") is expected
+
+
def
test_parquet_manifest_preserves_order_features_and_dataset_splits(tmp_path):
features = Features(
{
@@ -333,6 +365,7 @@ def
test_push_returns_commit_info_and_emits_matching_asset_event(tmp_path, hub_d
push_to_hub.assert_called_once()
kwargs = push_to_hub.call_args.kwargs
assert reference["fingerprint"] in kwargs["commit_message"]
+ assert kwargs.get("embed_external_files") is False
hf_api.return_value.list_repo_commits.assert_not_called()
assert result["commit_sha"] == commit.oid
assert result["commit_url"] == commit.commit_url
@@ -340,6 +373,23 @@ def
test_push_returns_commit_info_and_emits_matching_asset_event(tmp_path, hub_d
assert event.extra["commit_url"] == result["commit_url"]
+def test_push_kwargs_can_enable_embedding_external_files(tmp_path,
hub_dependencies):
+ _, push_to_hub = hub_dependencies
+ push_to_hub.return_value = commit_info()
+ reference = _save(Dataset.from_dict({"value": [1]}), (tmp_path /
"input.json").as_uri())
+
+ PushToHubOperator(
+ task_id="publish",
+ input_uri=reference,
+ repo_id="org/data",
+ push_kwargs={"embed_external_files": True},
+ huggingface_conn_id="huggingface_test",
+ durable=False,
+ ).execute({})
+
+ assert push_to_hub.call_args.kwargs["embed_external_files"] is True
+
+
def test_push_failure_propagates_and_emits_no_event(tmp_path,
hub_dependencies):
_, push_to_hub = hub_dependencies
reference = _save(Dataset.from_dict({"value": [1]}), (tmp_path /
"input.json").as_uri())