Skip to content

Commit ea2bf8f

Browse files
committed
fix workflow
1 parent 1cbcb6b commit ea2bf8f

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

.github/workflows/sdk-compliance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414
jobs:
1515
compliance:
1616
name: PostHog SDK compliance tests
17-
uses: PostHog/posthog-sdk-test-harness/.github/workflows/test-sdk-action.yml@v0.1
17+
uses: PostHog/posthog-sdk-test-harness/.github/workflows/test-sdk-action.yml@main
1818
with:
1919
adapter-dockerfile: "Dockerfile"
2020
adapter-context: "sdk_compliance_adapter"

sdk_compliance_adapter/adapter.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
It wraps the posthog-python SDK and exposes a REST API for the test harness to exercise.
66
"""
77

8-
import json
98
import logging
109
import os
1110
import threading
1211
import time
13-
from datetime import datetime
1412
from typing import Any, Dict, List, Optional
1513

1614
from flask import Flask, jsonify, request
1715

18-
from posthog import Client, Posthog
16+
from posthog import Client
1917
from posthog.request import batch_post as original_batch_post
2018
from posthog.version import VERSION
2119

@@ -31,7 +29,14 @@
3129
class RequestInfo:
3230
"""Information about an HTTP request made by the SDK"""
3331

34-
def __init__(self, timestamp_ms: int, status_code: int, retry_attempt: int, event_count: int, uuid_list: List[str]):
32+
def __init__(
33+
self,
34+
timestamp_ms: int,
35+
status_code: int,
36+
retry_attempt: int,
37+
event_count: int,
38+
uuid_list: List[str],
39+
):
3540
self.timestamp_ms = timestamp_ms
3641
self.status_code = status_code
3742
self.retry_attempt = retry_attempt
@@ -145,7 +150,13 @@ def create_batch_id(batch: List[Dict]) -> str:
145150
return "-".join(uuids[:3]) # Use first 3 UUIDs as batch ID
146151

147152

148-
def patched_batch_post(api_key: str, host: Optional[str] = None, gzip: bool = False, timeout: int = 15, **kwargs):
153+
def patched_batch_post(
154+
api_key: str,
155+
host: Optional[str] = None,
156+
gzip: bool = False,
157+
timeout: int = 15,
158+
**kwargs,
159+
):
149160
"""Patched version of batch_post that tracks requests"""
150161
batch = kwargs.get("batch", [])
151162
batch_id = create_batch_id(batch)
@@ -158,27 +169,35 @@ def patched_batch_post(api_key: str, host: Optional[str] = None, gzip: bool = Fa
158169
return response
159170
except Exception as e:
160171
# Record failed request
161-
status_code = getattr(e, "status_code", 500) if hasattr(e, "status_code") else 500
172+
status_code = (
173+
getattr(e, "status_code", 500) if hasattr(e, "status_code") else 500
174+
)
162175
state.record_request(status_code, batch, batch_id)
163176
state.record_error(str(e))
164177
raise
165178

166179

167180
# Monkey-patch the batch_post function
168-
import posthog.request
181+
import posthog.request # noqa: E402
169182

170183
posthog.request.batch_post = patched_batch_post
171184

172185
# Also patch in consumer module
173-
import posthog.consumer
186+
import posthog.consumer # noqa: E402
174187

175188
posthog.consumer.batch_post = patched_batch_post
176189

177190

178191
@app.route("/health", methods=["GET"])
179192
def health():
180193
"""Health check endpoint"""
181-
return jsonify({"sdk_name": "posthog-python", "sdk_version": VERSION, "adapter_version": "1.0.0"})
194+
return jsonify(
195+
{
196+
"sdk_name": "posthog-python",
197+
"sdk_version": VERSION,
198+
"adapter_version": "1.0.0",
199+
}
200+
)
182201

183202

184203
@app.route("/init", methods=["POST"])
@@ -294,7 +313,9 @@ def identify():
294313
state.increment_captured()
295314

296315
if properties_set_once:
297-
state.client.set_once(distinct_id=distinct_id, properties=properties_set_once)
316+
state.client.set_once(
317+
distinct_id=distinct_id, properties=properties_set_once
318+
)
298319
state.increment_captured()
299320

300321
logger.info(f"Identified user: {distinct_id}")

0 commit comments

Comments
 (0)