Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable geoip for capture and decide calls by default #98

Merged
merged 19 commits into from
Apr 17, 2023

Conversation

liyiy
Copy link
Contributor

@liyiy liyiy commented Apr 12, 2023

PostHog/posthog#14351

The $geoip property on server libraries tends to default to incorrect locations (mainly based from where the server is located and not the user) and causes issues such as incorrect event/user data for analytics and problems with feature flag rollouts based on location.

This fix prevents the advanced geoip plugin and the decide call in https://github.com/PostHog/posthog/blob/master/posthog/api/decide.py#L144 from overriding user properties with incorrect server library geoip properties by default.

Users who are manually passing in geoip values will have to set geoip_disable to False to ensure their values are not discarded

related PR: PostHog/posthog#15039

@liyiy liyiy changed the title Geoip disable Disable geoip for capture and decide calls Apr 12, 2023
@liyiy liyiy changed the title Disable geoip for capture and decide calls Disable geoip for capture and decide calls by default Apr 12, 2023
@liyiy liyiy requested a review from neilkakkar April 12, 2023 02:39
posthog/client.py Outdated Show resolved Hide resolved
@@ -112,7 +112,7 @@ def test_get_active_feature_flags(self, patch_decide):
}

client = Client(FAKE_TEST_API_KEY, on_error=self.set_fail, personal_api_key=FAKE_TEST_API_KEY)
variants = client._get_active_feature_variants("some_id", None, None, None)
variants = client._get_active_feature_variants("some_id", None, None, None, True)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, assert decide was called with the 'right' geoip_disable value.

Also add a similar test for capture, where you're not manually calling client._get_active_feature_variants but let capture call it

posthog/client.py Outdated Show resolved Hide resolved
@neilkakkar
Copy link
Collaborator

Users who are manually passing in geoip values will have to set geoip_disable to False to ensure their values are not discarded

This makes for an annoying user experience. I don't think we should have to force users to remember to set this setting, to make sure that their properties behave as expected.

Rather, we have very clear priority ordering here: if the user inputs anything, use that; if not, use the defaults. My previous comments in code are working towards this ideology.

@liyiy
Copy link
Contributor Author

liyiy commented Apr 12, 2023

Users who are manually passing in geoip values will have to set geoip_disable to False to ensure their values are not discarded

This makes for an annoying user experience. I don't think we should have to force users to remember to set this setting, to make sure that their properties behave as expected.

Rather, we have very clear priority ordering here: if the user inputs anything, use that; if not, use the defaults. My previous comments in code are working towards this ideology.

Right, but the default you're asking for is that it disables geoip by default.. so users will still have to manually set geoip_disable to False no?

@liyiy liyiy requested a review from neilkakkar April 12, 2023 20:19
Copy link
Collaborator

@neilkakkar neilkakkar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

posthog/client.py Outdated Show resolved Hide resolved
posthog/test/test_client.py Show resolved Hide resolved
@liyiy liyiy requested a review from neilkakkar April 13, 2023 16:46
return resp_data["featureFlags"]

def _get_active_feature_variants(self, distinct_id, groups=None, person_properties=None, group_properties=None):
feature_variants = self.get_feature_variants(distinct_id, groups, person_properties, group_properties)
def _get_active_feature_variants(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think this works for the case when someone calls posthog.capture(send_feature_flags=True, geoip_disable=False), or is tested yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh? what exactly would that test? If we're checking to see if setting a method geoip_disable param overrides the init one then the test in test_feature_flags should cover that, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the problem/issue here of why posthog.capture(send_feature_flags=True, geoip_disable=False) won't work?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/PostHog/posthog-python/blob/geoip-disable/posthog/client.py#L211

This is separate from test_feature_flags, it's for test_capture. In the line above^, we're not passing in geoip_disable coming from capture, which is why anything the user passes in there is discarded when it comes to _get_active_feature_variants

Copy link
Contributor Author

@liyiy liyiy Apr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I thought that would've been fine since it's a capture call that still hits the logic in enqueue for any geoip_disable stuff

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I guess what you're saying here is the feature flags that returns will be incorrect because geoip_disable isn't passed there, yes?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, so it will rightly not add geoip properties to the captured event, but wrongly add feature flags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we lead with that next time? 😁 I'm better at working backwards from the initial problem than building up to the problem, if that makes sense?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure I get it. Could you give me another example of what this means?

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