Extract public serialization helpers#330
Conversation
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughExtracts serialization helpers from app/main.py into a new app/serializers.py, updates app/main.py to import those helpers, and adds end-to-end tests that assert public JSON shapes remain unchanged. ChangesSerialization Module Extraction
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
ayskobtw-lil
left a comment
There was a problem hiding this comment.
No blockers from my review on current head f674c58fe297674236dce9f276575a661156d973.
Evidence checked:
- Inspected
app/main.py, the newapp/serializers.py, andtests/test_serializers.py. - Compared the extracted serializer helpers against the prior
app/main.pyimplementations for bounty rows/summaries, payout reconciliation rows, ledger rows, activity/account accepted-work summaries, wallet rows, and wallet transfer rows. - Verified route-layer imports still call the extracted helpers and keep auth/session/request handling in
app/main.py. - Verified the new serializer tests cover capacity fields, accepted-work summary/list shape, and wallet row shape.
Validation run locally:
python -m pytest tests/test_serializers.py tests/test_api_mcp.py::test_bounty_api_reports_multi_award_capacity tests/test_activity.py tests/test_wallet_api.py::test_wallet_api_register_lookup_and_transfer -q-> 7 passed.python -m ruff check app/main.py app/serializers.py tests/test_serializers.py-> passed.python -m ruff format --check app/main.py app/serializers.py tests/test_serializers.py-> passed.python -m mypy app/main.py app/serializers.py-> success.git diff --check origin/main...HEAD-> clean.
Residual risk is limited to moved helper behavior not covered by the focused tests, but the diff appears to preserve the existing public response shapes rather than changing semantics.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@app/serializers.py`:
- Around line 336-339: The helper _wallet_timestamp strips tzinfo then calls
isoformat, which is inconsistent with other serializers like
wallet_transfer_to_dict and can produce wrong times if inputs have non-UTC
tzinfo; change _wallet_timestamp to normalize datetimes to UTC (e.g., convert
via astimezone(timezone.utc) or otherwise ensure UTC) before formatting, and
update wallet_transfer_to_dict and any other serializers to call this single
helper so all timestamps are consistently normalized and serialized.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 6d1eb019-aeab-460d-bb52-c31544cc86fb
📒 Files selected for processing (3)
app/main.pyapp/serializers.pytests/test_serializers.py
| def _wallet_timestamp(value: datetime) -> str: | ||
| if value.tzinfo is not None: | ||
| value = value.replace(tzinfo=None) | ||
| return value.isoformat() |
There was a problem hiding this comment.
🧹 Nitpick | 🔵 Trivial | 💤 Low value
Inconsistent timestamp serialization across functions.
_wallet_timestamp strips tzinfo before calling isoformat(), but wallet_transfer_to_dict (line 365) and other serializers use .isoformat() directly. If the datetime source changes from UTC-only to mixed timezones, stripping tzinfo without conversion could produce incorrect results.
Current model defaults (utc_now) make this safe, but consider aligning all timestamp handling for consistency.
Also applies to: 365-365
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@app/serializers.py` around lines 336 - 339, The helper _wallet_timestamp
strips tzinfo then calls isoformat, which is inconsistent with other serializers
like wallet_transfer_to_dict and can produce wrong times if inputs have non-UTC
tzinfo; change _wallet_timestamp to normalize datetimes to UTC (e.g., convert
via astimezone(timezone.utc) or otherwise ensure UTC) before formatting, and
update wallet_transfer_to_dict and any other serializers to call this single
helper so all timestamps are consistently normalized and serialized.
f674c58 to
78dfd13
Compare
|
Small follow-up after CodeRabbit flagged docstring coverage: added concise docstrings to the new public serializer functions. Additional validation:
|
Refs #320
Summary
app/main.pyintoapp/serializers.py, covering bounty rows, bounty summaries, ledger rows, activity/account accepted-work summaries, wallet rows, and transfer rows.app/main.py; the extracted module now owns reusable public serialization behavior.Validation
uv run --extra dev python -m pytest tests/test_serializers.py tests/test_api_mcp.py::test_bounty_api_reports_multi_award_capacity tests/test_activity.py -q-> 6 passeduv run --extra dev python -m pytest tests/test_api_mcp.py tests/test_activity.py tests/test_wallet_api.py tests/test_security.py -q-> 154 passeduv run --extra dev python -m pytest -q-> 290 passeduv run --extra dev ruff check app/main.py app/serializers.py tests/test_serializers.py-> passeduv run --extra dev ruff format --check app/main.py app/serializers.py tests/test_serializers.py-> passeduv run --extra dev mypy app-> successgit diff --check-> passedSummary by CodeRabbit
Tests
Refactor