Skip to content

fix: stop duplicating distinct_id in flags person properties#207

Merged
marandaneto merged 4 commits into
mainfrom
fix/remove-flags-person-distinct-id
Jul 2, 2026
Merged

fix: stop duplicating distinct_id in flags person properties#207
marandaneto merged 4 commits into
mainfrom
fix/remove-flags-person-distinct-id

Conversation

@marandaneto

Copy link
Copy Markdown
Member

💡 Motivation and Context

/flags requests already send distinct_id at the top level. Automatically copying the same value into person_properties.distinct_id sends duplicated identity data and differs from the desired payload shape.

This PR keeps the top-level distinct_id and stops automatically injecting it into person_properties. Caller-provided person properties are still forwarded.

💚 How did you test it?

  • bundle config set path vendor/bundle && bundle install && bundle exec rspec spec/posthog/client_spec.rb spec/posthog/feature_flag_spec.rb

📝 Checklist

  • I reviewed the submitted code.
  • I added tests to verify the changes.
  • I updated the docs if needed.
  • No breaking change or entry added to the changelog.

If releasing new changes

  • Ran pnpm changeset to generate a changeset file

🤖 Agent context

Autonomy: Human-driven (agent-assisted)

This was implemented with pi in dedicated git worktrees. I changed the /flags request construction so SDKs keep the top-level distinct_id while no longer auto-copying it into person_properties; explicit caller-provided person_properties['distinct_id'] values are still preserved where covered.

@marandaneto marandaneto self-assigned this Jul 1, 2026
@github-actions

github-actions Bot commented Jul 1, 2026

Copy link
Copy Markdown

posthog-ruby Compliance Report

Date: 2026-07-02 11:40:58 UTC
Duration: 98512ms

⚠️ Some Tests Failed

44/46 tests passed, 2 failed


Capture Tests

29/29 tests passed

View Details
Test Status Duration
Format Validation.Event Has Required Fields 110ms
Format Validation.Event Has Uuid 105ms
Format Validation.Event Has Lib Properties 109ms
Format Validation.Distinct Id Is String 106ms
Format Validation.Token Is Present 106ms
Format Validation.Custom Properties Preserved 106ms
Format Validation.Event Has Timestamp 107ms
Retry Behavior.Retries On 503 5414ms
Retry Behavior.Does Not Retry On 400 2109ms
Retry Behavior.Does Not Retry On 401 2108ms
Retry Behavior.Respects Retry After Header 8117ms
Retry Behavior.Implements Backoff 15708ms
Retry Behavior.Retries On 500 5213ms
Retry Behavior.Retries On 502 5213ms
Retry Behavior.Retries On 504 5212ms
Retry Behavior.Max Retries Respected 15722ms
Deduplication.Generates Unique Uuids 112ms
Deduplication.Preserves Uuid On Retry 5212ms
Deduplication.Preserves Uuid And Timestamp On Retry 10413ms
Deduplication.Preserves Uuid And Timestamp On Batch Retry 5215ms
Deduplication.No Duplicate Events In Batch 112ms
Deduplication.Different Events Have Different Uuids 107ms
Compression.Sends Gzip When Enabled 107ms
Batch Format.Uses Proper Batch Structure 107ms
Batch Format.Flush With No Events Sends Nothing 5ms
Batch Format.Multiple Events Batched Together 110ms
Error Handling.Does Not Retry On 403 2109ms
Error Handling.Does Not Retry On 413 2109ms
Error Handling.Retries On 408 5212ms

Feature_Flags Tests

⚠️ 15/17 tests passed, 2 failed

View Details
Test Status Duration
Request Payload.Request With Person Properties Device Id 109ms
Request Payload.Flags Request Uses V2 Query Param 109ms
Request Payload.Flags Request Hits Flags Path Not Decide 110ms
Request Payload.Flags Request Omits Authorization Header 107ms
Request Payload.Token In Flags Body Matches Init 108ms
Request Payload.Groups Round Trip 107ms
Request Payload.Groups Default To Empty Object 108ms
Request Payload.Disable Geoip False Propagates As Geoip Disable False 107ms
Request Payload.Disable Geoip Omitted Defaults To False 108ms
Request Payload.Flag Keys To Evaluate Contains Only Requested Key 107ms
Request Lifecycle.No Flags Request On Init Alone 4ms
Request Lifecycle.No Flags Request On Normal Capture 106ms
Request Lifecycle.Two Flag Calls Produce Two Remote Requests 112ms
Request Lifecycle.Mock Response Value Is Returned To Caller 106ms
Retry Behavior.Retries Flags On 502 108ms
Retry Behavior.Retries Flags On 504 107ms
Side Effect Events.Get Feature Flag Captures Feature Flag Called Event 109ms

Failures

retry_behavior.retries_flags_on_502

Expected 2 /flags requests, got 1

retry_behavior.retries_flags_on_504

Expected 2 /flags requests, got 1

@greptile-apps

greptile-apps Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (1)

  1. lib/posthog/client.rb, line 1064-1073 (link)

    P2 Superfluous alias — all_person_properties is now a trivial alias for person_properties with no transformation applied. Under the "no superfluous parts" simplicity rule, the extra variable and the dead parameter distinct_id it used to consume can be removed, and the return value written directly.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "fix: stop duplicating distinct_id in fla..." | Re-trigger Greptile

Comment thread .changeset/quiet-wolves-fix.md
@marandaneto marandaneto marked this pull request as ready for review July 2, 2026 12:03
@marandaneto marandaneto requested a review from a team as a code owner July 2, 2026 12:03
@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Reviews (2): Last reviewed commit: "Keep distinct_id available for local fla..." | Re-trigger Greptile

@marandaneto marandaneto merged commit fcc6205 into main Jul 2, 2026
21 checks passed
@marandaneto marandaneto deleted the fix/remove-flags-person-distinct-id branch July 2, 2026 14:33
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.

2 participants