Skip to content

Add missing return statement in if_not_unset validator#1099

Open
bysiber wants to merge 1 commit intoagronholm:masterfrom
bysiber:fix/if-not-unset-missing-return
Open

Add missing return statement in if_not_unset validator#1099
bysiber wants to merge 1 commit intoagronholm:masterfrom
bysiber:fix/if-not-unset-missing-return

Conversation

@bysiber
Copy link
Contributor

@bysiber bysiber commented Feb 20, 2026

Summary

if_not_unset() defines an inner validate function but never returns it, so all attrs fields using this validator have no validation at all.

Problem

def if_not_unset(validator: Callable[[Any, Any, Any], None]) -> None:
    def validate(instance: Any, attribute: Any, value: Any) -> None:
        if value is unset:
            return
        validator(instance, attribute, value)
    # missing: return validate

The function implicitly returns None, so attrs treats the field as having no validator. This affects TaskDefaults.job_executor and all TaskParameters fields — they accept any value without validation.

Fix

Add return validate at the end of the function.

The if_not_unset function defines an inner validate function but
never returns it. This means attrs fields using if_not_unset get
None as their validator, effectively disabling all validation.
Copy link
Owner

@agronholm agronholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

@coveralls
Copy link

Coverage Status

coverage: 92.63%. first build
when pulling eebe2f4 on bysiber:fix/if-not-unset-missing-return
into f2337f7 on agronholm:master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants