Skip to content

NAS-140296 / 27.0.0-BETA.1 / Fix mock infrastructure to coerce dict results to Pydantic models for generic services#18457

Open
sonicaj wants to merge 1 commit intomasterfrom
fix-stig-test
Open

NAS-140296 / 27.0.0-BETA.1 / Fix mock infrastructure to coerce dict results to Pydantic models for generic services#18457
sonicaj wants to merge 1 commit intomasterfrom
fix-stig-test

Conversation

@sonicaj
Copy link
Member

@sonicaj sonicaj commented Mar 14, 2026

This commit fixes an issue where the mock infrastructure (test.set_mock) returns plain dicts for methods that internally return Pydantic models. Generic services (those with Config.generic = True) like DockerService return Pydantic model instances from their methods (e.g. docker.config returns a DockerEntry, docker.status returns a DockerStatusInfo). When internal callers use attribute access (e.g. .pool) on the result, mocks returning plain dicts would fail with "'dict' object has no attribute 'pool'".

The fix detects at mock registration time whether the mocked method belongs to a generic service and returns any Pydantic model. If so, the mock's dict results are automatically wrapped via model_construct() before being returned to callers. Non-generic services and primitive-returning methods are unaffected.

STIG tests: http://jenkins.eng.ixsystems.net:8080/job/tests/job/stig_tests/1812/ ( failing test was http://jenkins.eng.ixsystems.net:8080/job/tests/job/stig_tests/1811/testReport/junit/stig/test_01_stig/test_docker_apps_enabled_fail/ which has been fixed)

API tests: http://jenkins.eng.ixsystems.net:8080/job/tests/job/api_tests/8072/

@sonicaj sonicaj requested a review from a team March 14, 2026 22:17
@sonicaj sonicaj self-assigned this Mar 14, 2026
@bugclerk bugclerk changed the title Fix mock infrastructure to coerce dict results to Pydantic models for generic services NAS-140296 / 27.0.0-BETA.1 / Fix mock infrastructure to coerce dict results to Pydantic models for generic services Mar 14, 2026
@bugclerk
Copy link
Contributor

@truenas truenas deleted a comment from bugclerk Mar 14, 2026
… generic services

This commit fixes an issue where the mock infrastructure (test.set_mock)
returns plain dicts for methods that internally return Pydantic models.
Generic services (those with Config.generic = True) like DockerService
return Pydantic model instances from their methods (e.g. docker.config
returns a DockerEntry, docker.status returns a DockerStatusInfo). When
internal callers use attribute access (e.g. .pool) on the result, mocks
returning plain dicts would fail with "'dict' object has no attribute
'pool'".

The fix detects at mock registration time whether the mocked method
belongs to a generic service and returns any Pydantic model. If so, the
mock's dict results are automatically wrapped via model_construct()
before being returned to callers. Non-generic services and
primitive-returning methods are unaffected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants