Repository navigation
fix(segments): count contacts without the field as outside a referenced dynamic segment - #582
Open
joanproductivo wants to merge 1 commit into
Open
joanproductivo wants to merge 1 commit into
joanproductivo wants to merge 1 commit into
Conversation
…ed dynamic segment
notMemberOfSegment on a dynamic segment without membership tracking negated
that segment's filter. A data.* comparison on a contact without the key is NULL
in Postgres, and NOT NULL is still NULL, so "not in {plan = pro}" left out every
contact without a plan, including those created without data.
Every data.* comparison now requires its key first, so it is always true or
false and the negation is the segment's complement. On their own, filters match
the same contacts as before, except notEquals on a key explicitly set to null,
which no longer matches, as documented in operators.ts and as workflow
conditions already behave. equals/notEquals null still compare against a JSON
null. A value of another type than the filter (a number or an array for
contains) still matches neither side: Prisma's NOT on a typed JSON filter also
requires the type.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
notMemberOfSegmenton a dynamic segment that does not track membership negates that segment's filter. Adata.*comparison on a contact without the key is NULL in Postgres, andNOT NULLis still NULL, so the contact is dropped from both sides: "not in {plan = pro}" leaves out every contact without aplan, including contacts created without any data. Static and tracked segments are not affected (they go throughsegmentMemberships: {none}, added in #566).data.*comparison now requires its key first ({AND: [{NOT: missing}, comparison]}, withmissing={data: {path, equals: Prisma.AnyNull}}), so it is always true or false and the negation is the segment's complement.exists/notExistsproduce the same SQL as before (AnyNullis theOR[DbNull, JsonNull]they used, now written once).notEqualson a key explicitly set tonull, which no longer matches. That is whatoperators.tsdocuments and what workflow conditions already do.equals/notEqualswith anullvalue are left unwrapped, soequals nullstill matches a JSONnull, as in workflow conditions.notEquals/notContainsdo not change: contacts without the field still don't match them. The wiki now says so (instead of "Negation ofequals") and explains how to include them: OR the filter withnotExists, nested in the same group.containscompares text) matches neither side, because Prisma'sNOTon a typed JSON filter also requires the type.Cost: one extra
IS NULL OR = 'null'perdata.*leaf. Measured on 200,000 contacts, both before and after are a sequential scan (the#>path never used the GIN index), about +6 ms.Type of Change
feat:New feature (MINOR version bump)fix:Bug fix (PATCH version bump)feat!:Breaking change - new feature (MAJOR version bump)fix!:Breaking change - bug fix (MAJOR version bump)docs:Documentation update (no version bump)chore:Maintenance/dependencies (no version bump)refactor:Code refactoring (no version bump)test:Adding tests (no version bump)perf:Performance improvement (PATCH version bump)Testing
SegmentService.segmentFilters.test.tsgains 12 tests, throughSegmentService.create/getContacts, with contacts that have the field,{}, a key set tonull, a JSONnullcolumn (whatContactService.createstores without data) and a NULL column:notMemberOfSegmentofequals,notEquals,contains,notContainsandexistssegments; a chain of two untracked dynamic segments; a value of another type (the known gap);notEquals/equalswith a key set tonull;exists/notExistswithout data; and the nested OR withnotExists, next to another filter (an unsubscribed contact checks it stays inside the group) and alone. Without the fix, 6 of them fail.nextwith the change: 1664 tests passing. ESLint--max-warnings 0andtsc --noEmitclean for api.Checklist
Related Issues
Follow-up to #566.
🤖 Generated with Claude Code