Skip to content

Conversation

@hunterino
Copy link
Owner

Summary

Fixed a bug where EntityFindBase.oneInternal() would strip all non-PK conditions when a full primary key was provided, treating them as "over-constrained".

Root Cause

Lines 783-796 in EntityFindBase.groovy contained logic that:

  1. Detected when a full PK was present along with additional conditions
  2. Created a new map containing ONLY the PK fields
  3. Replaced the original condition map, silently discarding all non-PK conditions

Example of the Bug

// Before fix: status condition was silently IGNORED
ec.entity.find("Order")
    .condition("orderId", "12345")      // PK
    .condition("orderStatus", "ACTIVE") // Non-PK - WAS DISCARDED!
    .one()
// Would return order 12345 regardless of its status!

The Fix

  • Removed the problematic code block (14 lines deleted)
  • Added explanatory comment documenting the fix
  • Added comprehensive test case

Test Plan

  • Added test "find with PK and non-PK conditions should honor all conditions"
  • Verified fix compiles
  • Run full test suite (./gradlew test)

Upstream Reference

Fixes #14

🤖 Generated with Claude Code

)

Previously, EntityFindBase.oneInternal() would strip all non-PK conditions
when a full primary key was provided, treating them as "over-constrained".
This was semantically incorrect as users may legitimately want to validate
additional conditions alongside PK lookups (e.g., status checks).

Changes:
- Removed the code block that discarded non-PK conditions (lines 783-796)
- Added test to verify non-PK conditions are honored with PK queries

Before: ec.entity.find("Entity").condition("pk", "1").condition("status", "ACTIVE")
        would ignore the status condition entirely.

After: Both pk AND status conditions are included in the query.

Fixes #14

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@hunterino hunterino merged commit eec5156 into master Dec 21, 2025
2 of 3 checks passed
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.

[P1] Entity find ignores non-PK conditions

2 participants