Skip to content

Possible breaking change with handling of nil conditions in 3.5.0 #821

@CJStadler

Description

@CJStadler

Steps to reproduce

In #653 the handling of nil with has_many relations was changed. Previously a rule like

can :read, Document, authors: { user_id: nil }

caused can? :read, document to be true only if document has an author with user_id: nil. In 3.5.0 this behavior has changed and can? :read, document will also be true if document has no authors.

I'm not sure what the better behavior is, but this seems like a breaking change as applications using earlier versions may have been depending on the previous behavior.

Gist with a test case: https://gist.github.com/CJStadler/2d6e6644a72286c823d71c3b96b92a80

Expected behavior

Upgrading a minor version does not change the behavior of existing rules.

Actual behavior

Upgrading from 3.4.0 to 3.5.0 changed the behavior of existing rules, authorizing users to access resources that they were not previously authorized to access.

System configuration

Rails version:
6.1.7
Ruby version:
2.7.5
CanCanCan version
3.5.0

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