Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition validation failure leaves field in unvalidated state #80

Open
thismatters opened this issue Feb 19, 2024 · 0 comments
Open

Comments

@thismatters
Copy link

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!

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

No branches or pull requests

1 participant