chore: serialization/pandas modernization, settings hardening, race fixes#187
Merged
Conversation
- streamer: serialize WS payloads via pydantic model_dump(mode="json"), dropping
the global json.JSONEncoder monkeypatch and redundant json.loads(json.dumps())
round-trips (byte-identical wire output). Remove the unused, latently-recursive
uuid_json_encoder.
- mixins: LogicalDeletionMixin.delete() now returns Django's (count, {label:count})
tuple; drop the redundant double save() in the consumer and the dead
database_delete_room method.
- consumers: make host promotion on leave atomic (select_for_update). Fixes a race
where the chosen next host could leave between selection and promotion; the old
.earliest() also raised DoesNotExist -> 1011 close when the room emptied.
- settings: replace ALLOWED_HOSTS += ['*'] under DEBUG with an explicit dev
allowlist (prevents Host-header injection if DEBUG ever ships to prod).
- api: drop the heavy pandas dependency; fill per-day gaps with a plain loop.
- tests: await the database_sync_to_async existence helpers (asserts were no-ops
on a coroutine and emitted 'never awaited' warnings).
| import uuid | ||
|
|
||
| from channels.db import database_sync_to_async | ||
| from django.db import transaction |
Contributor
There was a problem hiding this comment.
🚫 [mypy] reported by reviewdog 🐶
Cannot find implementation or library stub for module named "django.db" [import-not-found]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
コードレビューに基づくモダナイズとバグ/競合修正。WebSocket プロトコルのワイヤ形式は不変です。
変更点
モダナイズ
model_dump(mode="json")に統一。グローバルなjson.JSONEncoder.defaultモンキーパッチと冗長なjson.loads(json.dumps(...))往復を全廃(出力は従来とバイト単位で同一)。
(
uv.lockから numpy/pytz/tzdata 等も削減)。バグ / 競合修正
leave_partyのホスト委譲をselect_for_updateでアトミック化。旧実装は「次ホスト選定 → 昇格」の await 境界で当人が離脱すると論理削除済みの行を昇格させ、
さらに
.earliest()が空室時にDoesNotExistを投げて 1011 close を招いていた。uuid_json_encoderを削除。LogicalDeletionMixin.delete()が Django 標準の(count, {label: count})を返すよう修正。consumer の冗長な二重
save()と、未使用のdatabase_delete_roomを削除。database_sync_to_asyncヘルパのawait漏れを修正(アサートがコルーチンオブジェクトに対する no-op になっており、"never awaited" 警告も出ていた)。
セキュリティ
DEBUG時のALLOWED_HOSTS += ["*"]を明示的な dev 許可リストへ変更(DEBUG=1 のまま本番に出た場合の Host ヘッダインジェクションを防止)。
検証
ruff check/ruff format --check: クリーンpython manage.py makemigrations --check: 変更なしpytest: 26 passed("never awaited" 警告も解消)