You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "sidshas03 (via GitHub)" <gi...@apache.org> on 2025/09/16 00:46:35 UTC
[PR] Fix airflowctl create assets command not working [airflow]
sidshas03 opened a new pull request, #55702:
URL: https://github.com/apache/airflow/pull/55702
Resolves #55697
Problem:
- airflowctl create assets command was failing because the required API endpoint and client method were missing
- Users could not create assets via the CLI tool
Root Cause:
- Missing POST /assets endpoint in Airflow core API
- Missing create() method in AssetsOperations class
- Missing CreateAssetBody data model for asset creation requests
Solution:
1. Added CreateAssetBody data model with proper validation:
- name (required, 1-1500 chars)
- uri (required, 1-1500 chars)
- group (optional, max 1500 chars)
- extra (optional dict)
2. Implemented POST /assets API endpoint with:
- Duplicate asset checking (name + uri uniqueness)
- Proper error handling (400 for bad requests, 409 for conflicts)
- Authentication and authorization
- Action logging for audit trails
3. Added create() method to AssetsOperations class:
- Proper HTTP POST request handling
- JSON serialization with date safety
- Error handling and response parsing
4. Updated generated datamodels to include CreateAssetBody
Testing:
- Verified airflowctl assets create command is now available
- Confirmed parameter validation works correctly
- Tested API integration (fails gracefully when no server/credentials)
- All linting checks pass
The airflowctl create assets command now works as expected and allows users to create assets via the CLI.
--
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 airflowctl create assets command not working [airflow]
Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on code in PR #55702:
URL: https://github.com/apache/airflow/pull/55702#discussion_r2353341260
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets_post.py:
##########
@@ -0,0 +1,75 @@
+# Licensed to the Apache Software Foundation (ASF) under one
Review Comment:
I think this test should be directly in the same file name matching with the assets.py. Thanks for including the tests!
##########
airflow-ctl/src/airflowctl/api/operations.py:
##########
@@ -238,6 +239,16 @@ def list_by_alias(self) -> AssetAliasCollectionResponse | ServerResponseError:
"""List all assets by alias from the API server."""
return super().execute_list(path="/assets/aliases", data_model=AssetAliasCollectionResponse)
+ def create(self, asset_body: CreateAssetBody) -> AssetResponse | ServerResponseError:
+ """Create an asset."""
+ try:
+ self.response = self.client.post(
+ "assets", json=_date_safe_dict_from_pydantic(asset_body)
+ )
+ return AssetResponse.model_validate_json(self.response.content)
+ except ServerResponseError as e:
+ raise e
+
def create_event(
Review Comment:
Connected issue #55697 is related to this
--
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 airflowctl create assets command not working [airflow]
Posted by "sidshas03 (via GitHub)" <gi...@apache.org>.
sidshas03 commented on PR #55702:
URL: https://github.com/apache/airflow/pull/55702#issuecomment-3304033525
> You will need to re-run pre commit hooks. (generate the new API spec + UI codegen step)
Good point, I’ve dropped the Field(...) min/max constraints and kept plain str for name, uri, and group. I re-ran pre-commit (including the API spec + UI codegen) and pushed, then updated the branch on top of main.
If you’d prefer a minimal min_length=1 on name/uri, happy to add that back, but I agree the DB will enforce overly long inputs.
--
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 airflowctl create assets command not working [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #55702:
URL: https://github.com/apache/airflow/pull/55702#issuecomment-3688263679
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.
--
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 airflowctl create assets command not working [airflow]
Posted by "sidshas03 (via GitHub)" <gi...@apache.org>.
sidshas03 commented on PR #55702:
URL: https://github.com/apache/airflow/pull/55702#issuecomment-3304170114
**Update:** Incorporated review feedback and added coverage.
**Latest commits:**
• `e084c8f` — *fix(api): simplify assets datamodel to plain `str`; regen OpenAPI/UI client* (drops the `Field(..., min_length/max_length)` constraints in `CreateAssetBody`). ([GitHub][3])
• `24ec0bc` — *tests(api): POST /assets* — adds FastAPI tests for happy path, 409 duplicate, 4xx validation, and auth.
--
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 airflowctl create assets command not working [airflow]
Posted by "jason810496 (via GitHub)" <gi...@apache.org>.
jason810496 commented on code in PR #55702:
URL: https://github.com/apache/airflow/pull/55702#discussion_r2362192472
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -1361,3 +1361,542 @@ def test_should_respond_404(self, test_client):
response.json()["detail"]
== "Queued event with dag_id: `not_exists` and asset_id: `1` was not found"
)
+
+
+class TestPostAssets:
+ """Test POST /assets endpoint with comprehensive parametrized tests."""
+
+ @pytest.fixture(autouse=True)
+ def setup(self):
+ clear_db_assets()
+ yield
+ clear_db_assets()
Review Comment:
We could inherent `TestAssets` base test class to simplify the setup.
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -1361,3 +1361,542 @@ def test_should_respond_404(self, test_client):
response.json()["detail"]
== "Queued event with dag_id: `not_exists` and asset_id: `1` was not found"
)
+
+
+class TestPostAssets:
+ """Test POST /assets endpoint with comprehensive parametrized tests."""
+
+ @pytest.fixture(autouse=True)
+ def setup(self):
+ clear_db_assets()
+ yield
+ clear_db_assets()
+
+ @pytest.mark.parametrize(
+ "payload,expected_status,expected_fields",
+ [
+ # Happy path cases
+ (
+ {"name": "s3_my_dataset", "uri": "s3://bucket/path", "group": "raw", "extra": {"owner": "data-eng"}},
+ 201,
+ {"name": "s3_my_dataset", "uri": "s3://bucket/path", "group": "raw", "extra": {"owner": "data-eng"}},
+ ),
+ (
+ {"name": "only_required", "uri": "s3://b/k"},
+ 201,
+ {"name": "only_required", "uri": "s3://b/k", "group": None, "extra": None},
+ ),
+ (
+ {"name": "gcs_asset", "uri": "gs://my-bucket/data", "group": "processed"},
+ 201,
+ {"name": "gcs_asset", "uri": "gs://my-bucket/data", "group": "processed"},
+ ),
+ (
+ {"name": "azure_asset", "uri": "wasb://container@account.blob.core.windows.net/path"},
+ 201,
+ {"name": "azure_asset", "uri": "wasb://container@account.blob.core.windows.net/path"},
+ ),
+ ],
+ ids=["with_all_fields", "only_required_fields", "gcs_uri", "azure_uri"],
+ )
+ def test_assets_create_success_cases(self, test_client, payload, expected_status, expected_fields):
+ """Test successful asset creation with various payloads."""
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == expected_status
+ body = resp.json()
+
+ # Check response structure
+ assert isinstance(body, dict)
+ assert "id" in body
+ assert "created_at" in body
+ assert "updated_at" in body
+
+ # Check expected fields
+ for field, expected_value in expected_fields.items():
+ assert body[field] == expected_value
Review Comment:
The test case will be more readable by asserting with the expected dict directly. For example:
https://github.com/apache/airflow/blob/main/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py#L923-L936
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -1361,3 +1361,542 @@ def test_should_respond_404(self, test_client):
response.json()["detail"]
== "Queued event with dag_id: `not_exists` and asset_id: `1` was not found"
)
+
+
+class TestPostAssets:
+ """Test POST /assets endpoint with comprehensive parametrized tests."""
+
+ @pytest.fixture(autouse=True)
+ def setup(self):
+ clear_db_assets()
+ yield
+ clear_db_assets()
+
+ @pytest.mark.parametrize(
+ "payload,expected_status,expected_fields",
+ [
+ # Happy path cases
+ (
+ {"name": "s3_my_dataset", "uri": "s3://bucket/path", "group": "raw", "extra": {"owner": "data-eng"}},
+ 201,
+ {"name": "s3_my_dataset", "uri": "s3://bucket/path", "group": "raw", "extra": {"owner": "data-eng"}},
+ ),
+ (
+ {"name": "only_required", "uri": "s3://b/k"},
+ 201,
+ {"name": "only_required", "uri": "s3://b/k", "group": None, "extra": None},
+ ),
+ (
+ {"name": "gcs_asset", "uri": "gs://my-bucket/data", "group": "processed"},
+ 201,
+ {"name": "gcs_asset", "uri": "gs://my-bucket/data", "group": "processed"},
+ ),
+ (
+ {"name": "azure_asset", "uri": "wasb://container@account.blob.core.windows.net/path"},
+ 201,
+ {"name": "azure_asset", "uri": "wasb://container@account.blob.core.windows.net/path"},
+ ),
+ ],
+ ids=["with_all_fields", "only_required_fields", "gcs_uri", "azure_uri"],
+ )
+ def test_assets_create_success_cases(self, test_client, payload, expected_status, expected_fields):
+ """Test successful asset creation with various payloads."""
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == expected_status
+ body = resp.json()
+
+ # Check response structure
+ assert isinstance(body, dict)
+ assert "id" in body
+ assert "created_at" in body
+ assert "updated_at" in body
+
+ # Check expected fields
+ for field, expected_value in expected_fields.items():
+ assert body[field] == expected_value
+
+ @pytest.mark.parametrize(
+ "payload,expected_status,expected_error_pattern",
+ [
+ # 400 Bad Request cases
+ ({"name": "", "uri": "s3://bucket/key"}, 400, "name"),
+ ({"name": "valid_name", "uri": ""}, 400, "uri"),
+ ({"name": "x" * 1501, "uri": "s3://bucket/key"}, 400, "name"),
+ ({"name": "valid_name", "uri": "x" * 1501}, 400, "uri"),
+
+ # 422 Unprocessable Entity cases
+ ({"name": 123, "uri": "s3://bucket/key"}, 422, "name"),
+ ({"name": "valid_name", "uri": ["not-a-string"]}, 422, "uri"),
+ ({"name": None, "uri": "s3://bucket/key"}, 422, "name"),
+ ({"name": "valid_name", "uri": None}, 422, "uri"),
+ ({"extra": "not-a-dict", "name": "valid_name", "uri": "s3://bucket/key"}, 422, "extra"),
+ ({"group": 123, "name": "valid_name", "uri": "s3://bucket/key"}, 422, "group"),
+
+ # Missing required fields
+ ({"uri": "s3://bucket/key"}, 422, "name"),
+ ({"name": "valid_name"}, 422, "uri"),
+ ({}, 422, "name"),
+ ],
+ ids=[
+ "empty_name", "empty_uri", "name_too_long", "uri_too_long",
+ "name_not_string", "uri_not_string", "name_none", "uri_none",
+ "extra_not_dict", "group_not_string", "missing_name", "missing_uri", "missing_both"
+ ],
+ )
+ def test_assets_create_validation_errors(self, test_client, payload, expected_status, expected_error_pattern):
+ """Test validation error cases with various invalid payloads."""
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == expected_status
+
+ if resp.headers.get("content-type", "").startswith("application/json"):
+ error_body = resp.json()
+ assert isinstance(error_body, dict)
+ # Check that error message contains expected pattern
+ error_detail = error_body.get("detail", "")
+ assert expected_error_pattern in str(error_detail).lower()
+
+ def test_assets_create_conflict_returns_409(self, test_client):
+ """Test that creating duplicate assets returns 409 Conflict."""
+ from uuid import uuid4
+ uniq = uuid4().hex[:8]
+ payload = {"name": f"dup_asset_{uniq}", "uri": f"s3://bucket/key-{uniq}"}
+
+ # First creation should succeed
+ r1 = test_client.post("/assets", json=payload)
+ assert r1.status_code == 201
+
+ # Second creation with same name+uri should fail
+ r2 = test_client.post("/assets", json=payload)
+ assert r2.status_code == 409
+
+ # Check error response structure
+ if r2.headers.get("content-type", "").startswith("application/json"):
+ error_body = r2.json()
+ assert isinstance(error_body, dict)
+ assert "detail" in error_body
+ assert "already exists" in error_body["detail"].lower() or "conflict" in error_body["detail"].lower()
+
+ @pytest.mark.parametrize(
+ "client_fixture,expected_status",
+ [
+ ("unauthenticated_test_client", 401),
+ ("unauthorized_test_client", 403),
+ ],
+ ids=["unauthenticated_401", "unauthorized_403"],
+ )
+ def test_assets_create_auth_errors(self, request, client_fixture, expected_status):
+ """Test authentication and authorization error cases."""
+ client = request.getfixturevalue(client_fixture)
+ payload = {"name": "test_asset", "uri": "s3://bucket/test"}
+
+ resp = client.post("/assets", json=payload)
+ assert resp.status_code == expected_status
+
+ if resp.headers.get("content-type", "").startswith("application/json"):
+ error_body = resp.json()
+ assert isinstance(error_body, dict)
+ assert "detail" in error_body
+
+ def test_assets_create_with_special_characters(self, test_client):
+ """Test asset creation with special characters in name and URI."""
+ payload = {
+ "name": "asset-with-dashes_and_underscores.and.dots",
+ "uri": "s3://bucket-name/path/with/special-chars_123",
+ "group": "test-group",
+ "extra": {"special": "chars", "unicode": "测试", "numbers": 123}
+ }
+
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == 201
+
+ body = resp.json()
+ assert body["name"] == payload["name"]
+ assert body["uri"] == payload["uri"]
+ assert body["group"] == payload["group"]
+ assert body["extra"] == payload["extra"]
+
+ def test_assets_create_response_structure(self, test_client):
+ """Test that the response has the correct structure and all required fields."""
+ payload = {"name": "structure_test", "uri": "s3://bucket/structure"}
+
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == 201
+
+ body = resp.json()
+
+ # Required fields
+ required_fields = ["id", "name", "uri", "group", "extra", "created_at", "updated_at"]
+ for field in required_fields:
+ assert field in body, f"Missing required field: {field}"
+
+ # Check field types
+ assert isinstance(body["id"], int)
+ assert isinstance(body["name"], str)
+ assert isinstance(body["uri"], str)
+ assert body["group"] is None or isinstance(body["group"], str)
+ assert body["extra"] is None or isinstance(body["extra"], dict)
+ assert isinstance(body["created_at"], str)
+ assert isinstance(body["updated_at"], str)
+
+ # Check timestamps are valid ISO format
+ from datetime import datetime
+ datetime.fromisoformat(body["created_at"].replace("Z", "+00:00"))
+ datetime.fromisoformat(body["updated_at"].replace("Z", "+00:00"))
Review Comment:
It seems we can remove these test cases, as the above test cases will be sufficient enough.
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/assets.py:
##########
@@ -160,6 +160,20 @@ class QueuedEventCollectionResponse(BaseModel):
total_entries: int
+class CreateAssetBody(StrictBaseModel):
+ """Create asset request."""
+
+ name: str
+ uri: str
+ group: str
+ extra: dict = Field(default_factory=dict)
+
+ class Config:
+ """Pydantic config."""
+
+ extra = "forbid"
Review Comment:
It would be better to follow the Pydantic V2 syntax.
```suggestion
model_config = ConfigDict(extra="forbid")
```
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -1361,3 +1361,542 @@ def test_should_respond_404(self, test_client):
response.json()["detail"]
== "Queued event with dag_id: `not_exists` and asset_id: `1` was not found"
)
+
+
+class TestPostAssets:
+ """Test POST /assets endpoint with comprehensive parametrized tests."""
+
+ @pytest.fixture(autouse=True)
+ def setup(self):
+ clear_db_assets()
+ yield
+ clear_db_assets()
+
+ @pytest.mark.parametrize(
+ "payload,expected_status,expected_fields",
+ [
+ # Happy path cases
+ (
+ {"name": "s3_my_dataset", "uri": "s3://bucket/path", "group": "raw", "extra": {"owner": "data-eng"}},
+ 201,
+ {"name": "s3_my_dataset", "uri": "s3://bucket/path", "group": "raw", "extra": {"owner": "data-eng"}},
+ ),
+ (
+ {"name": "only_required", "uri": "s3://b/k"},
+ 201,
+ {"name": "only_required", "uri": "s3://b/k", "group": None, "extra": None},
+ ),
+ (
+ {"name": "gcs_asset", "uri": "gs://my-bucket/data", "group": "processed"},
+ 201,
+ {"name": "gcs_asset", "uri": "gs://my-bucket/data", "group": "processed"},
+ ),
+ (
+ {"name": "azure_asset", "uri": "wasb://container@account.blob.core.windows.net/path"},
+ 201,
+ {"name": "azure_asset", "uri": "wasb://container@account.blob.core.windows.net/path"},
+ ),
+ ],
+ ids=["with_all_fields", "only_required_fields", "gcs_uri", "azure_uri"],
+ )
+ def test_assets_create_success_cases(self, test_client, payload, expected_status, expected_fields):
+ """Test successful asset creation with various payloads."""
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == expected_status
+ body = resp.json()
+
+ # Check response structure
+ assert isinstance(body, dict)
+ assert "id" in body
+ assert "created_at" in body
+ assert "updated_at" in body
+
+ # Check expected fields
+ for field, expected_value in expected_fields.items():
+ assert body[field] == expected_value
+
+ @pytest.mark.parametrize(
+ "payload,expected_status,expected_error_pattern",
+ [
+ # 400 Bad Request cases
+ ({"name": "", "uri": "s3://bucket/key"}, 400, "name"),
+ ({"name": "valid_name", "uri": ""}, 400, "uri"),
+ ({"name": "x" * 1501, "uri": "s3://bucket/key"}, 400, "name"),
+ ({"name": "valid_name", "uri": "x" * 1501}, 400, "uri"),
+
+ # 422 Unprocessable Entity cases
+ ({"name": 123, "uri": "s3://bucket/key"}, 422, "name"),
+ ({"name": "valid_name", "uri": ["not-a-string"]}, 422, "uri"),
+ ({"name": None, "uri": "s3://bucket/key"}, 422, "name"),
+ ({"name": "valid_name", "uri": None}, 422, "uri"),
+ ({"extra": "not-a-dict", "name": "valid_name", "uri": "s3://bucket/key"}, 422, "extra"),
+ ({"group": 123, "name": "valid_name", "uri": "s3://bucket/key"}, 422, "group"),
+
+ # Missing required fields
+ ({"uri": "s3://bucket/key"}, 422, "name"),
+ ({"name": "valid_name"}, 422, "uri"),
+ ({}, 422, "name"),
+ ],
+ ids=[
+ "empty_name", "empty_uri", "name_too_long", "uri_too_long",
+ "name_not_string", "uri_not_string", "name_none", "uri_none",
+ "extra_not_dict", "group_not_string", "missing_name", "missing_uri", "missing_both"
+ ],
+ )
+ def test_assets_create_validation_errors(self, test_client, payload, expected_status, expected_error_pattern):
+ """Test validation error cases with various invalid payloads."""
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == expected_status
+
+ if resp.headers.get("content-type", "").startswith("application/json"):
+ error_body = resp.json()
+ assert isinstance(error_body, dict)
+ # Check that error message contains expected pattern
+ error_detail = error_body.get("detail", "")
+ assert expected_error_pattern in str(error_detail).lower()
+
+ def test_assets_create_conflict_returns_409(self, test_client):
+ """Test that creating duplicate assets returns 409 Conflict."""
+ from uuid import uuid4
+ uniq = uuid4().hex[:8]
+ payload = {"name": f"dup_asset_{uniq}", "uri": f"s3://bucket/key-{uniq}"}
+
+ # First creation should succeed
+ r1 = test_client.post("/assets", json=payload)
+ assert r1.status_code == 201
+
+ # Second creation with same name+uri should fail
+ r2 = test_client.post("/assets", json=payload)
+ assert r2.status_code == 409
+
+ # Check error response structure
+ if r2.headers.get("content-type", "").startswith("application/json"):
+ error_body = r2.json()
+ assert isinstance(error_body, dict)
+ assert "detail" in error_body
+ assert "already exists" in error_body["detail"].lower() or "conflict" in error_body["detail"].lower()
+
+ @pytest.mark.parametrize(
+ "client_fixture,expected_status",
+ [
+ ("unauthenticated_test_client", 401),
+ ("unauthorized_test_client", 403),
+ ],
+ ids=["unauthenticated_401", "unauthorized_403"],
+ )
+ def test_assets_create_auth_errors(self, request, client_fixture, expected_status):
+ """Test authentication and authorization error cases."""
+ client = request.getfixturevalue(client_fixture)
+ payload = {"name": "test_asset", "uri": "s3://bucket/test"}
+
+ resp = client.post("/assets", json=payload)
+ assert resp.status_code == expected_status
+
+ if resp.headers.get("content-type", "").startswith("application/json"):
+ error_body = resp.json()
+ assert isinstance(error_body, dict)
+ assert "detail" in error_body
Review Comment:
```suggestion
```
##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_assets.py:
##########
@@ -1361,3 +1361,542 @@ def test_should_respond_404(self, test_client):
response.json()["detail"]
== "Queued event with dag_id: `not_exists` and asset_id: `1` was not found"
)
+
+
+class TestPostAssets:
+ """Test POST /assets endpoint with comprehensive parametrized tests."""
+
+ @pytest.fixture(autouse=True)
+ def setup(self):
+ clear_db_assets()
+ yield
+ clear_db_assets()
+
+ @pytest.mark.parametrize(
+ "payload,expected_status,expected_fields",
+ [
+ # Happy path cases
+ (
+ {"name": "s3_my_dataset", "uri": "s3://bucket/path", "group": "raw", "extra": {"owner": "data-eng"}},
+ 201,
+ {"name": "s3_my_dataset", "uri": "s3://bucket/path", "group": "raw", "extra": {"owner": "data-eng"}},
+ ),
+ (
+ {"name": "only_required", "uri": "s3://b/k"},
+ 201,
+ {"name": "only_required", "uri": "s3://b/k", "group": None, "extra": None},
+ ),
+ (
+ {"name": "gcs_asset", "uri": "gs://my-bucket/data", "group": "processed"},
+ 201,
+ {"name": "gcs_asset", "uri": "gs://my-bucket/data", "group": "processed"},
+ ),
+ (
+ {"name": "azure_asset", "uri": "wasb://container@account.blob.core.windows.net/path"},
+ 201,
+ {"name": "azure_asset", "uri": "wasb://container@account.blob.core.windows.net/path"},
+ ),
+ ],
+ ids=["with_all_fields", "only_required_fields", "gcs_uri", "azure_uri"],
+ )
+ def test_assets_create_success_cases(self, test_client, payload, expected_status, expected_fields):
+ """Test successful asset creation with various payloads."""
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == expected_status
+ body = resp.json()
+
+ # Check response structure
+ assert isinstance(body, dict)
+ assert "id" in body
+ assert "created_at" in body
+ assert "updated_at" in body
+
+ # Check expected fields
+ for field, expected_value in expected_fields.items():
+ assert body[field] == expected_value
+
+ @pytest.mark.parametrize(
+ "payload,expected_status,expected_error_pattern",
+ [
+ # 400 Bad Request cases
+ ({"name": "", "uri": "s3://bucket/key"}, 400, "name"),
+ ({"name": "valid_name", "uri": ""}, 400, "uri"),
+ ({"name": "x" * 1501, "uri": "s3://bucket/key"}, 400, "name"),
+ ({"name": "valid_name", "uri": "x" * 1501}, 400, "uri"),
+
+ # 422 Unprocessable Entity cases
+ ({"name": 123, "uri": "s3://bucket/key"}, 422, "name"),
+ ({"name": "valid_name", "uri": ["not-a-string"]}, 422, "uri"),
+ ({"name": None, "uri": "s3://bucket/key"}, 422, "name"),
+ ({"name": "valid_name", "uri": None}, 422, "uri"),
+ ({"extra": "not-a-dict", "name": "valid_name", "uri": "s3://bucket/key"}, 422, "extra"),
+ ({"group": 123, "name": "valid_name", "uri": "s3://bucket/key"}, 422, "group"),
+
+ # Missing required fields
+ ({"uri": "s3://bucket/key"}, 422, "name"),
+ ({"name": "valid_name"}, 422, "uri"),
+ ({}, 422, "name"),
+ ],
+ ids=[
+ "empty_name", "empty_uri", "name_too_long", "uri_too_long",
+ "name_not_string", "uri_not_string", "name_none", "uri_none",
+ "extra_not_dict", "group_not_string", "missing_name", "missing_uri", "missing_both"
+ ],
+ )
+ def test_assets_create_validation_errors(self, test_client, payload, expected_status, expected_error_pattern):
+ """Test validation error cases with various invalid payloads."""
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == expected_status
+
+ if resp.headers.get("content-type", "").startswith("application/json"):
+ error_body = resp.json()
+ assert isinstance(error_body, dict)
+ # Check that error message contains expected pattern
+ error_detail = error_body.get("detail", "")
+ assert expected_error_pattern in str(error_detail).lower()
+
+ def test_assets_create_conflict_returns_409(self, test_client):
+ """Test that creating duplicate assets returns 409 Conflict."""
+ from uuid import uuid4
+ uniq = uuid4().hex[:8]
+ payload = {"name": f"dup_asset_{uniq}", "uri": f"s3://bucket/key-{uniq}"}
+
+ # First creation should succeed
+ r1 = test_client.post("/assets", json=payload)
+ assert r1.status_code == 201
+
+ # Second creation with same name+uri should fail
+ r2 = test_client.post("/assets", json=payload)
+ assert r2.status_code == 409
+
+ # Check error response structure
+ if r2.headers.get("content-type", "").startswith("application/json"):
+ error_body = r2.json()
+ assert isinstance(error_body, dict)
+ assert "detail" in error_body
+ assert "already exists" in error_body["detail"].lower() or "conflict" in error_body["detail"].lower()
+
+ @pytest.mark.parametrize(
+ "client_fixture,expected_status",
+ [
+ ("unauthenticated_test_client", 401),
+ ("unauthorized_test_client", 403),
+ ],
+ ids=["unauthenticated_401", "unauthorized_403"],
+ )
+ def test_assets_create_auth_errors(self, request, client_fixture, expected_status):
+ """Test authentication and authorization error cases."""
+ client = request.getfixturevalue(client_fixture)
+ payload = {"name": "test_asset", "uri": "s3://bucket/test"}
+
+ resp = client.post("/assets", json=payload)
+ assert resp.status_code == expected_status
+
+ if resp.headers.get("content-type", "").startswith("application/json"):
+ error_body = resp.json()
+ assert isinstance(error_body, dict)
+ assert "detail" in error_body
+
+ def test_assets_create_with_special_characters(self, test_client):
+ """Test asset creation with special characters in name and URI."""
+ payload = {
+ "name": "asset-with-dashes_and_underscores.and.dots",
+ "uri": "s3://bucket-name/path/with/special-chars_123",
+ "group": "test-group",
+ "extra": {"special": "chars", "unicode": "测试", "numbers": 123}
+ }
+
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == 201
+
+ body = resp.json()
+ assert body["name"] == payload["name"]
+ assert body["uri"] == payload["uri"]
+ assert body["group"] == payload["group"]
+ assert body["extra"] == payload["extra"]
+
+ def test_assets_create_response_structure(self, test_client):
+ """Test that the response has the correct structure and all required fields."""
+ payload = {"name": "structure_test", "uri": "s3://bucket/structure"}
+
+ resp = test_client.post("/assets", json=payload)
+ assert resp.status_code == 201
+
+ body = resp.json()
+
+ # Required fields
+ required_fields = ["id", "name", "uri", "group", "extra", "created_at", "updated_at"]
+ for field in required_fields:
+ assert field in body, f"Missing required field: {field}"
+
+ # Check field types
+ assert isinstance(body["id"], int)
+ assert isinstance(body["name"], str)
+ assert isinstance(body["uri"], str)
+ assert body["group"] is None or isinstance(body["group"], str)
+ assert body["extra"] is None or isinstance(body["extra"], dict)
+ assert isinstance(body["created_at"], str)
+ assert isinstance(body["updated_at"], str)
+
+ # Check timestamps are valid ISO format
+ from datetime import datetime
+ datetime.fromisoformat(body["created_at"].replace("Z", "+00:00"))
+ datetime.fromisoformat(body["updated_at"].replace("Z", "+00:00"))
+
+
+class TestPostAssetEventsComprehensive:
Review Comment:
Same, we can remove the whole `TestPostAssetEventsComprehensive` test class.
##########
.gitignore:
##########
@@ -277,3 +277,4 @@ _api/
go-sdk/**/*.log
_e2e_test_report.json
+.breeze310/
Review Comment:
The change seems not related
```suggestion
```
--
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 airflowctl create assets command not working [airflow]
Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on PR #55702:
URL: https://github.com/apache/airflow/pull/55702#issuecomment-3308803336
This isn't related to the connected ticket which is a bug and is a new feature
--
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 airflowctl create assets command not working [airflow]
Posted by "sidshas03 (via GitHub)" <gi...@apache.org>.
sidshas03 commented on PR #55702:
URL: https://github.com/apache/airflow/pull/55702#issuecomment-3310148143
**What I updated in this PR:**
* **airflow-ctl:** fixed `assets create` and `assets create-event` wiring.
* **Tests (ctl):** replaced `httpx`/transport mocks with `pytest.monkeypatch` so the lane doesn’t depend on extra packages; assertions verify:
* `create()` → `POST /assets` with `{name, uri}`
* `create_event()` → `POST /assets/events` with `{asset_id, extra}` (defaults to `{}`)
* **OpenAPI & client:** regenerated OpenAPI spec and refreshed the Python client so new endpoints are present.
* **Datamodels:** ensured `CreateAssetBody` is present and `group` is treated as a required `str`.
* **Static/typing:** cleaned imports and Py3.10-friendly typing; local Breeze runs show ctl tests and python-client tests passing.
Latest commit: **b1782f7**.
Once CI is approved and running, I’ll watch the lanes and address anything that pops up. 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 airflowctl create assets command not working [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #55702:
URL: https://github.com/apache/airflow/pull/55702#discussion_r2355883197
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/assets.py:
##########
@@ -160,6 +160,20 @@ class QueuedEventCollectionResponse(BaseModel):
total_entries: int
+class CreateAssetBody(StrictBaseModel):
+ """Create asset request."""
+
+ name: str = Field(..., min_length=1, max_length=1500)
+ uri: str = Field(..., min_length=1, max_length=1500)
+ group: str = Field(default="", max_length=1500)
Review Comment:
You don't need to do that.
The DB will refuse such wrong input (if strings are too long), then the AIP & UI should gracefully handle and display this error.
Can you update and confirm please?
```suggestion
name: str
uri: str
group: str
```
--
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 airflowctl create assets command not working [airflow]
Posted by "sidshas03 (via GitHub)" <gi...@apache.org>.
sidshas03 commented on PR #55702:
URL: https://github.com/apache/airflow/pull/55702#issuecomment-3312906756
I’ve aligned the POST `/assets` tests with the current API (200 success, 422 validation, `group` required) and verified locally: the `airflow-ctl` assets suite is green. There’s one remaining conflict in `airflow-ctl/tests/airflow_ctl/api/test_operations.py` caused by base-branch drift. I’m resolving it now by keeping the passing version from this branch and will push a rebase to re-trigger CI. After that, we should be good for a full run. 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 airflowctl create assets command not working [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #55702: Fix airflowctl create assets command not working
URL: https://github.com/apache/airflow/pull/55702
--
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 airflowctl create assets command not working [airflow]
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #55702:
URL: https://github.com/apache/airflow/pull/55702#issuecomment-3303494809
You will need to re-run pre commit hooks. (generate the new API spec + UI codegen step)
--
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 airflowctl create assets command not working [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #55702:
URL: https://github.com/apache/airflow/pull/55702#issuecomment-3483158767
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.
--
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 airflowctl create assets command not working [airflow]
Posted by "sidshas03 (via GitHub)" <gi...@apache.org>.
sidshas03 commented on PR #55702:
URL: https://github.com/apache/airflow/pull/55702#issuecomment-3300753549
Thanks, @bugraoz93 and @jason810496!
• I’ll move the tests into the existing test_assets.py so the filename matches assets.py.
• I’ll also add 422 to the endpoint’s documented responses and make the CTL client use absolute "/assets" for consistency.
• Re: the connected story; this PR fixes the create asset path; the separate create_event issue in airflowctl will be handled in a follow-up. I’ll update the PR description to say “Related to #55697” (not auto-close).
--
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 airflowctl create assets command not working [airflow]
Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on PR #55702:
URL: https://github.com/apache/airflow/pull/55702#issuecomment-3487438424
This won't be in the first release so I will check out afterwards. We should focus on releasing airflowctl where we can add new features at any time from there if not breaking after 1.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