Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/sweet-ravens-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'pypi/posthog': patch
---

Send batch `sent_at` using the backend-supported snake_case field.
2 changes: 1 addition & 1 deletion posthog/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def post(
"""Post the `kwargs` to the API"""
log = logging.getLogger("posthog")
body = kwargs
body["sentAt"] = datetime.now(tz=timezone.utc).isoformat()
body["sent_at"] = datetime.now(tz=timezone.utc).isoformat()
trimmed_host = remove_trailing_slash(normalize_host(host))
url = trimmed_host + cast(str, path)
body["api_key"] = api_key
Expand Down
25 changes: 25 additions & 0 deletions posthog/test/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@ def test_mask_tokens_in_url(url, expected):
assert _mask_tokens_in_url(url) == expected


@pytest.mark.parametrize(
"key, expected_present",
[
("sent_at", True),
("sentAt", False),
],
)
def test_post_sends_snake_case_sent_at(key, expected_present):
mock_response = requests.Response()
mock_response.status_code = 200
mock_session = mock.MagicMock()
mock_session.post.return_value = mock_response

request_module.post(
TEST_API_KEY,
host="https://test.posthog.com",
path="/batch/",
session=mock_session,
batch=[],
)

data = json.loads(mock_session.post.call_args.kwargs["data"])
assert (key in data) is expected_present


class TestRequests(unittest.TestCase):
def test_valid_request(self):
res = batch_post(
Expand Down
Loading