Skip to content

Conversation

@jurajmajerik
Copy link
Contributor

@jurajmajerik jurajmajerik commented Aug 19, 2025

Closes #306

@PostHog/team-feature-flags This fixes the immediate crash issue - the broader suggestion about wrapping all SDK calls in try/except is worth considering.

Problem

The SDK crashes with 'NoneType' object has no attribute 'get' when group_properties is None.

Changes

Handle None group_properties by defaulting to an empty dict before calling .get().

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR fixes a critical bug in the PostHog Python SDK where the client would crash with a 'NoneType' object has no attribute 'get' error when group_properties is None. The issue occurs in the _add_local_person_and_group_properties method when users provide groups but leave group_properties as None, which is a valid use case according to the method signature and SDK design.

The fix is a simple but important defensive programming change on line 2000 of posthog/client.py. The code was changed from **(group_properties.get(group_name) or {}) to **((group_properties or {}).get(group_name) or {}). This ensures that if group_properties is None, it gets replaced with an empty dictionary before attempting to call the .get() method.

This change brings consistency to the codebase, as the same defensive pattern is already used for person_properties handling elsewhere (e.g., line 1992 uses **(person_properties or {})). The fix integrates seamlessly with the existing parameter validation and property aggregation logic that merges person and group properties for feature flag evaluation and event tracking.

Confidence score: 5/5

  • This PR is extremely safe to merge with virtually no risk of introducing issues
  • Score reflects a simple, well-targeted fix that follows existing patterns in the codebase and addresses a clear crash scenario
  • No files require special attention as this is a straightforward defensive programming fix

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@jurajmajerik jurajmajerik requested a review from a team August 19, 2025 16:01
@dmarticus dmarticus moved this to In Review in Feature Flags Aug 19, 2025
Copy link
Contributor

@dmarticus dmarticus left a comment

Choose a reason for hiding this comment

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

adding, thanks for fixing! Agreed we should try/catch here; we do it in other places in our SDK

@github-project-automation github-project-automation bot moved this from In Review to Approved in Feature Flags Aug 19, 2025
@dmarticus dmarticus merged commit ae97131 into master Aug 19, 2025
11 checks passed
@dmarticus dmarticus deleted the fix-group-properties-nonetype branch August 19, 2025 19:01
@github-project-automation github-project-automation bot moved this from Approved to Done in Feature Flags Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

'NoneType' object has no attribute 'get'

3 participants