Skip to content

False positive Packwerk violation for polymorphic belongs_to :event association #19

@ivy

Description

@ivy

We’re seeing a false positive pks when defining a polymorphic belongs_to :event association in a model. Even though the association is polymorphic and doesn’t reference a specific model, a privacy and dependency violation is triggered referencing a model named Event in a different pack.

Context:

In a model within Pack A, we have the following line:

belongs_to :event, polymorphic: true

This is intended to be a generic polymorphic association and does not directly reference the Event model defined in Pack B. However, the tooling is inferring a direct dependency on that model purely based on the association name.

Violation Output:

Privacy Violation: `::Event` belongs to Pack B, which is not visible to Pack A.
Dependency Violation: `::Event` belongs to Pack B, but Pack A does not declare it as a dependency.

Expected Behavior:

A polymorphic association like belongs_to :event, polymorphic: true should not result in a violation unless the code explicitly references a concrete class or constant from another pack.

Temporary Workaround:

  • Add a TODO to suppress the violation using bin/pks update
  • Alternatively, rename the association (e.g. :related_event) to avoid triggering the incorrect inference (though this breaks with established naming conventions)

Notes:

  • bin/packwerk check and bin/pks check produce the same result
  • Slack thread (Gusto internal)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions