Skip to content

Return response objects from all client methods#122

Merged
hownowstephen merged 2 commits intomainfrom
MESS-675_return-response-objects
May 8, 2026
Merged

Return response objects from all client methods#122
hownowstephen merged 2 commits intomainfrom
MESS-675_return-response-objects

Conversation

@hownowstephen
Copy link
Copy Markdown
Contributor

@hownowstephen hownowstephen commented May 7, 2026

Summary

  • send_request() now returns the requests.Response object instead of response.text
  • Track API methods (identify, track, pageview, backfill, delete, add_device, delete_device, suppress, unsuppress, merge_customers) now return the response instead of None
  • APIClient methods (send_email, send_push, etc.) continue to return parsed JSON dicts — switched from json.loads(resp) to resp.json()

Breaking change

Track API methods previously returned None. Code that checked result is None or relied on the falsy return will need updating. However, the most common usage pattern (cio.identify(...) without capturing return) is unaffected.

Example

# Before: no way to inspect the response
cio.identify(id="123", name="Alice")

# After: response available if needed
resp = cio.identify(id="123", name="Alice")
print(resp.status_code)  # 200

Closes #85

Test plan

  • Updated test_client_base.py assertions for Response objects
  • All existing Track API tests pass (use hooks, don't assert return values)
  • All existing APIClient tests pass (return value contract unchanged — still dicts)
  • Full test suite passes (28 tests)
  • Lint passes

Note

Medium Risk
This is a small but behavior-changing API shift: send_request and all Track API calls now return requests.Response, which may break callers that assumed None/string returns or compared return values directly. Core request/response handling is touched, but logic changes are straightforward and covered by updated tests.

Overview
Updates the core HTTP layer so ClientBase.send_request() returns the full requests.Response object (instead of response.text).

Propagates this through the Track client so methods like identify, track, delete, merge_customers, and batch now return the response rather than None, enabling callers to inspect status codes/headers.

Keeps APIClient return values as parsed JSON dicts, but switches parsing to resp.json() and removes the now-unused json import. Tests are updated to assert on Response attributes (e.g., status_code) instead of raw strings.

Reviewed by Cursor Bugbot for commit b07b660. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a91619d. Configure here.

Comment thread tests/test_client_base.py
Comment thread customerio/track.py
send_request() now returns the requests.Response object instead of
response.text. Track API methods (identify, track, etc.) return the
response instead of None, letting callers inspect status codes, headers,
and body. APIClient methods continue to return parsed JSON dicts.

Closes #85
Update test_2xx_status_codes_accepted to assert on Response object
instead of text. Add missing return to batch() method.
@hownowstephen hownowstephen force-pushed the MESS-675_return-response-objects branch from a91619d to b07b660 Compare May 8, 2026 01:26
@hownowstephen hownowstephen merged commit 02c0e14 into main May 8, 2026
10 checks passed
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.

returning responses rather than None

2 participants