Skip to content

Transition validation failure leaves field in unvalidated state #80

@thismatters

Description

@thismatters

Hello, I'm doing some unittesting around a workflow which is enabled by django-enumfield enum __transitions__, and I'm seeing something unexpected. Suppose we had:

class StatusEnum(Enum):
    NEW = 0
    PENDING = 1
    UNREACHABLE = 3

    __default__ = NEW

    __transitions__ = {
        NEW: (PENDING,),
        PENDING: (NEW,),
        UNREACHABLE: (PENDING,),

    }


class WorkflowModel(models.Model):
    status = EnumField(StatusEnum)

Then, if I were to run something like:

assert workflow_instance.status == StatusEnum.NEW

try:
    workflow_instance.status = StatusEnum.UNREACHABLE
except InvalidStatusOperationError:
    pass

assert workflow_instance.status == StatusEnum.UNREACHABLE

No AssertionError would raise! The status of the field will appear as UNREACHABLE, even though that should be impossible as the change did not pass validation. The behavior I expected was that the field value would be returned to it's pre-validation value (namely NEW). As I write this I'm realizing that the existing behavior permits bypassing validation, which may be a feature, and not a bug; so a change may not really be necessary.

Thanks for this package, it is great and necessary!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions