mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-02-19 06:30:07 +00:00
refactor: use explicit dataclasses instead of ORM objects in service layer
Replace dict/ORM object returns with explicit dataclasses to fix DetachedInstanceError when accessing ORM attributes after session closes. - Add app/assets/services/schemas.py with AssetData, AssetInfoData, AssetDetailResult, and RegisterAssetResult dataclasses - Update asset_management.py and ingest.py to return dataclasses - Update manager.py to use attribute access on dataclasses - Fix created_new to be False in create_asset_from_hash (content exists) - Add DependencyMissingError for better blake3 missing error handling - Update tests to use attribute access instead of dict subscripting Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -55,9 +55,9 @@ class TestGetAssetDetail:
|
||||
result = get_asset_detail(asset_info_id=info.id)
|
||||
|
||||
assert result is not None
|
||||
assert result["info"].id == info.id
|
||||
assert result["asset"].id == asset.id
|
||||
assert set(result["tags"]) == {"alpha", "beta"}
|
||||
assert result.info.id == info.id
|
||||
assert result.asset.hash == asset.hash
|
||||
assert set(result.tags) == {"alpha", "beta"}
|
||||
|
||||
def test_respects_owner_visibility(self, mock_create_session, session: Session):
|
||||
asset = _make_asset(session)
|
||||
@@ -102,8 +102,8 @@ class TestUpdateAssetMetadata:
|
||||
tags=["new1", "new2"],
|
||||
)
|
||||
|
||||
assert set(result["tags"]) == {"new1", "new2"}
|
||||
assert "old" not in result["tags"]
|
||||
assert set(result.tags) == {"new1", "new2"}
|
||||
assert "old" not in result.tags
|
||||
|
||||
def test_updates_user_metadata(self, mock_create_session, session: Session):
|
||||
asset = _make_asset(session)
|
||||
|
||||
@@ -163,8 +163,8 @@ class TestRegisterExistingAsset:
|
||||
tags=["models"],
|
||||
)
|
||||
|
||||
assert result["created"] is True
|
||||
assert "models" in result["tags"]
|
||||
assert result.created is True
|
||||
assert "models" in result.tags
|
||||
|
||||
# Verify by re-fetching from DB
|
||||
session.expire_all()
|
||||
@@ -197,7 +197,7 @@ class TestRegisterExistingAsset:
|
||||
owner_id="",
|
||||
)
|
||||
|
||||
assert result["created"] is False
|
||||
assert result.created is False
|
||||
|
||||
# Verify only one AssetInfo exists for this name
|
||||
session.expire_all()
|
||||
@@ -223,5 +223,5 @@ class TestRegisterExistingAsset:
|
||||
tags=["alpha", "beta"],
|
||||
)
|
||||
|
||||
assert result["created"] is True
|
||||
assert set(result["tags"]) == {"alpha", "beta"}
|
||||
assert result.created is True
|
||||
assert set(result.tags) == {"alpha", "beta"}
|
||||
|
||||
Reference in New Issue
Block a user