fix: resolve Pydantic 2.13 type mismatch for random_user_agent field#505
fix: resolve Pydantic 2.13 type mismatch for random_user_agent field#505Watermelcn wants to merge 1 commit into
Conversation
WalkthroughThis change resolves a Pydantic 2.13 type validation error that crashed the panel on startup. The ChangesPydantic Type Validation Fix
🎯 2 (Simple) | ⏱️ ~10 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
app/core/hosts.py (1)
361-361:⚠️ Potential issue | 🔴 Critical | ⚡ Quick winMissing string conversion for
random_user_agentinSubscriptionInboundData.This line passes
host.random_user_agentdirectly without thestr()conversion applied to all the transport config assignments above. SinceSubscriptionInboundData.random_user_agentis now typed asstr, passing a boolean/int from the database will trigger the same Pydantic 2.13 validation error this PR aims to fix.🐛 Proposed fix
random_user_agent=host.random_user_agent, + random_user_agent=str(host.random_user_agent) if host.random_user_agent is not None else "",🤖 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/core/hosts.py` at line 361, The SubscriptionInboundData construction is passing host.random_user_agent directly but the model now expects a str; change the assignment to convert to string (e.g., set random_user_agent=str(host.random_user_agent)) similar to the other transport config fields to avoid Pydantic validation errors; update the spot where SubscriptionInboundData (or the builder creating it) assigns random_user_agent so it always supplies a string even if host.random_user_agent is bool/int/None.
🤖 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.
Outside diff comments:
In `@app/core/hosts.py`:
- Line 361: The SubscriptionInboundData construction is passing
host.random_user_agent directly but the model now expects a str; change the
assignment to convert to string (e.g., set
random_user_agent=str(host.random_user_agent)) similar to the other transport
config fields to avoid Pydantic validation errors; update the spot where
SubscriptionInboundData (or the builder creating it) assigns random_user_agent
so it always supplies a string even if host.random_user_agent is bool/int/None.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ac2c0d1c-99fc-462d-a031-daa0d9f19a40
📒 Files selected for processing (2)
app/core/hosts.pyapp/models/subscription.py
|
its been more 2 year since i added this feature in marzban and have always been bool |
Description
Fix #504 — Panel crashes on startup because
random_user_agentfield type wasboolbut Pydantic 2.13 strictly enforces validation and throwsTypeErrorwhen trying to apply a stringpatternconstraint to a boolean/int value.Changes
app/models/subscription.py
Changed
random_user_agentfield type frombool = Field(False)tostr = Field("")across 5 model classes:GRPCTransportConfigWebSocketTransportConfigXHTTPTransportConfigTCPTransportConfigSubscriptionInboundDataapp/core/hosts.py
Added safe string conversion when reading
random_user_agentfrom database host records across all 5 transport initialization blocks (xhttp, grpc, ws/websocket, tcp/raw/http/h2, unknown default):Verification
Fix details
🤖 Automatically generated by bounty-worker-v2
Closes #504
Summary by CodeRabbit