-
Notifications
You must be signed in to change notification settings - Fork 14
Fix create_user at Stream and AsyncStream
#207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
- ID is not always random (previously was randomly generated only once on import) - "image" param is passed to the API
WalkthroughModified the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
getstream/stream.py (2)
215-228: Consider usingNoneinstead of empty string for optionalimageparameter.The fix for ID generation is correct—moving UUID generation from default argument to runtime avoids the classic Python pitfall where default mutable/computed values are evaluated only once at definition time.
However, the
imageparameter defaults to""and is always passed toUserRequest. According toUserRequest's definition,imageisOptional[str]with defaultNone. Passing an empty string when no image is intended could differ semantically from passingNone(or omitting it), potentially causing unexpected API behavior.🔎 Suggested fix
async def create_user( - self, name: str = "", id: str = "", image: str = "" + self, name: str = "", id: str = "", image: Optional[str] = None ) -> FullUserResponse: """ Creates or updates users. This method performs an "upsert" operation, where it checks if each user already exists and updates their information if they do, or creates a new user entry if they do not. """ id = id or str(uuid4()) - user = UserRequest(name=name, id=id, image=image) + user = UserRequest(name=name, id=id, image=image if image else None)
334-347: Same recommendation applies: useOptional[str] = Noneforimage.The core fixes are correct:
- ID generation at runtime instead of definition time ✓
imageparameter is now passed toUserRequest✓- Return type annotation added ✓
Apply the same refactor suggested for
AsyncStream.create_userto keep both methods consistent.🔎 Suggested fix
def create_user( - self, name: str = "", id: str = "", image: str = "" + self, name: str = "", id: str = "", image: Optional[str] = None ) -> FullUserResponse: """ Creates or updates users. This method performs an "upsert" operation, where it checks if each user already exists and updates their information if they do, or creates a new user entry if they do not. """ id = id or str(uuid4()) - user = UserRequest(name=name, id=id, image=image) + user = UserRequest(name=name, id=id, image=image if image else None)
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
getstream/stream.py
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py
📄 CodeRabbit inference engine (AGENTS.md)
Plugins that work with audio, video, or WebRTC functionality should depend on
getstream[webrtc]instead of justgetstreamto access WebRTC-related dependencies likeaiortc,numpy,torch,torchaudio,soundfile,scipy,deepgram-sdk, andelevenlabs
Files:
getstream/stream.py
🧬 Code graph analysis (1)
getstream/stream.py (1)
getstream/models/__init__.py (2)
FullUserResponse(8957-9057)UserRequest(19883-19907)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Tests (3.11)
- GitHub Check: Tests (3.12)
- GitHub Check: Tests (3.10)
- GitHub Check: Tests (3.13)
🔇 Additional comments (1)
getstream/stream.py (1)
17-17: LGTM!Import of
FullUserResponseis appropriate for the new return type annotations.
Also fixes #200
Summary by CodeRabbit
New Features
Changes
✏️ Tip: You can customize this high-level summary in your review settings.