fix: ingest 落库 SDK timezone 到 Visitor.timezone_name(Task16 联调发现)

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
浅念
2026-09-15 16:59:24 +08:00
parent 0fa51e77ef
commit e56f252ffd
2 changed files with 11 additions and 0 deletions
+3
View File
@@ -42,6 +42,9 @@ def _geo_field(g, key):
def _touch_visitor(site, vid, ctx, ip):
env = {k: str(ctx.get(k, "") or "")[:n] for k, n in _FIELD_LEN.items()}
# Task16 联调发现:键名映射缺口——SDK context 发 "timezone",模型字段是 timezone_name,
# 同名推导的 _FIELD_LEN 取不到值,导致 timezone_name 恒空。
env["timezone_name"] = str(ctx.get("timezone", "") or "")[:64]
v, created = Visitor.objects.get_or_create(
site=site, visitor_id=vid, defaults={**env, "last_ip": ip})
now = timezone.now()
+8
View File
@@ -134,3 +134,11 @@ def test_missing_payload_fields_rejected(db):
p = _batch([_ev(1)])
del p["session_id"]
assert ingest_batch(site, p)["rejected"] == [{"reason": "invalid_payload"}]
# 14. SDK context 的 timezone 落库 Visitor.timezone_name(Task16 联调发现:键名映射缺口)
def test_context_timezone_persisted_to_visitor(db):
site = Site.objects.create(name="s", domains=["a.com"])
b = _batch([_ev(1)])
b["context"]["timezone"] = "Asia/Shanghai"
ingest_batch(site, b)
assert Visitor.objects.get(visitor_id="v1").timezone_name == "Asia/Shanghai"