Skip to content

Commit f1b4229

Browse files
committed
Expose repo security status field in ModelInfo (#2639)
* expose repo security status in ModelInfo * remove warning in test
1 parent de9e7ee commit f1b4229

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,8 @@ class ModelInfo:
774774
List of spaces using the model.
775775
safetensors (`SafeTensorsInfo`, *optional*):
776776
Model's safetensors information.
777+
security_repo_status (`Dict`, *optional*):
778+
Model's security scan status.
777779
"""
778780

779781
id: str
@@ -802,6 +804,7 @@ class ModelInfo:
802804
siblings: Optional[List[RepoSibling]]
803805
spaces: Optional[List[str]]
804806
safetensors: Optional[SafeTensorsInfo]
807+
security_repo_status: Optional[Dict]
805808

806809
def __init__(self, **kwargs):
807810
self.id = kwargs.pop("id")
@@ -867,7 +870,7 @@ def __init__(self, **kwargs):
867870
if safetensors
868871
else None
869872
)
870-
873+
self.security_repo_status = kwargs.pop("securityRepoStatus", None)
871874
# backwards compatibility
872875
self.lastModified = self.last_modified
873876
self.cardData = self.card_data
@@ -2489,7 +2492,7 @@ def model_info(
24892492
Whether to set a timeout for the request to the Hub.
24902493
securityStatus (`bool`, *optional*):
24912494
Whether to retrieve the security status from the model
2492-
repository as well.
2495+
repository as well. The security status will be returned in the `security_repo_status` field.
24932496
files_metadata (`bool`, *optional*):
24942497
Whether or not to retrieve metadata for files in the repository
24952498
(size, LFS metadata, etc). Defaults to `False`.

tests/test_hf_api.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,21 +1821,16 @@ def test_model_info(self):
18211821
self.assertIsInstance(model, ModelInfo)
18221822
self.assertEqual(model.sha, DUMMY_MODEL_ID_REVISION_ONE_SPECIFIC_COMMIT)
18231823

1824-
# TODO; un-skip this test once it's fixed.
1825-
@unittest.skip(
1826-
"Security status is currently unreliable on the server endpoint, so this"
1827-
" test occasionally fails. Issue is tracked in"
1828-
" https://github.com/huggingface/huggingface_hub/issues/1002 and"
1829-
" https://github.com/huggingface/moon-landing/issues/3695. TODO: un-skip"
1830-
" this test once it's fixed."
1831-
)
18321824
def test_model_info_with_security(self):
1825+
# Note: this test might break in the future if `security_repo_status` object structure gets updated server-side
1826+
# (not yet fully stable)
18331827
model = self._api.model_info(
18341828
repo_id=DUMMY_MODEL_ID,
18351829
revision=DUMMY_MODEL_ID_REVISION_ONE_SPECIFIC_COMMIT,
18361830
securityStatus=True,
18371831
)
1838-
self.assertEqual(model.securityStatus, {"containsInfected": False})
1832+
self.assertIsNotNone(model.security_repo_status)
1833+
self.assertEqual(model.security_repo_status, {"scansDone": True, "filesWithIssues": []})
18391834

18401835
def test_model_info_with_file_metadata(self):
18411836
model = self._api.model_info(

0 commit comments

Comments
 (0)