Repository navigation
fix: send alias through the configured Consumer's transport - #208
Draft
rahul-mixpanel wants to merge 2 commits into
Draft
rahul-mixpanel wants to merge 2 commits into
rahul-mixpanel wants to merge 2 commits into
Conversation
Mixpanel.alias() always built a bare Consumer(), so it ignored the api_host (EU/IN data residency), timeouts, retries and verify_cert of the Consumer or BufferedConsumer passed to Mixpanel(). Alias is still sent synchronously: a Consumer is used directly, and a BufferedConsumer's inner Consumer is used so the buffer is bypassed. Custom consumers keep the previous default Consumer() behaviour. Related to #101 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #208 +/- ##
==========================================
+ Coverage 96.51% 96.54% +0.02%
==========================================
Files 15 15
Lines 2955 2977 +22
Branches 180 182 +2
==========================================
+ Hits 2852 2874 +22
Misses 66 66
Partials 37 37
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
[Medium impact] The PR appears safe to merge. Reviews (2) · Last reviewed commit: "fix: fall back to default Consumer when ..." · Reviewed by Greptile |
… consumer Avoids AttributeError for BufferedConsumer subclasses that skip super().__init__() and for Mock(spec=BufferedConsumer) in user tests. Also assert the alias URL and payload in the api_host test. Related to #101 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Related to #101 · Linear SDK-370
Problem
Mixpanel.alias()always created a newConsumer(). Settings on the consumer you passed toMixpanel(...)were ignored, includingapi_host,request_timeout,retry_limitandverify_cert. So a project usingapi_host="api-eu.mixpanel.com"(EU data residency) still sent$create_aliasto the US host.Change
alias()still sends synchronously, as the docstring promises. It now reuses the transport you configured:Consumer(exact type): used directly.BufferedConsumer(including subclasses): its innerConsumeris used, so the alias skips the buffer and is sent right away. If there is no inner consumer, alias falls back to a defaultConsumer(), as before. That covers a subclass that skipssuper().__init__()and aMock(spec=BufferedConsumer).Consumer(), because these consumers may not send synchronously. This includes custom consumers andConsumersubclasses.Known limitation (open design question): a
Consumersubclass configured with, say, the EU host still sends alias to the default US host. This PR checks the type exactly (type(...) is Consumer), so a subclass that overridessend()to queue or defer delivery can't make alias asynchronous. Usingisinstance(..., Consumer)instead would cover those subclasses' hosts too, at that small risk. The current behaviour is deliberately left as is, pending a decision.The payload is unchanged, and so is the public API.
Cross-SDK parity
alias): callstrack("$create_alias"), so it uses the configured host. This change matches it.Alias): uses the client's configured host. This change matches it.createAlias): turns offfork/async, then sends through the configured consumer strategy, including user-registered strategies. So PHP does send alias through a custom consumer. It just forces the built-in strategies to be synchronous.alias): always builds a freshConsumer, regardless of the configured consumer. It accepts an optionalevents_endpoint.Routing alias through fully custom consumers, which #101 and #114 ask for, is out of scope here. That is flagged on the Linear ticket for a decision.
Tests
test_alias_uses_configured_api_host, parametrised overConsumerandBufferedConsumer, checks that alias goes tohttps://api-eu.mixpanel.com/trackwith the expected payload, and that aBufferedConsumersends it immediately.test_alias_with_mocked_buffered_consumerchecks that aMock(spec=BufferedConsumer)falls back to the defaultConsumer()instead of raisingAttributeError.ruff checkandruff format --checkare clean.🤖 Generated with Claude Code