Skip to content

Commit 7a2ba0c

Browse files
committed
Fix create_user at Stream and AsyncStream
- ID is not always random (previously was randomly generated only once on import) - "image" param is passed to the API
1 parent 30dc844 commit 7a2ba0c

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

getstream/stream.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from getstream.common.async_client import CommonClient as AsyncCommonClient
1515
from getstream.common.client import CommonClient
1616
from getstream.feeds.client import FeedsClient
17-
from getstream.models import UserRequest
17+
from getstream.models import FullUserResponse, UserRequest
1818
from getstream.moderation.client import ModerationClient
1919
from getstream.moderation.async_client import ModerationClient as AsyncModerationClient
2020
from getstream.utils import validate_and_clean_url
@@ -212,13 +212,16 @@ def feeds(self):
212212
raise NotImplementedError("Feeds not supported for async client")
213213

214214
@telemetry.operation_name("getstream.api.common.create_user")
215-
async def create_user(self, name: str = "", id: str = str(uuid4()), image=""):
215+
async def create_user(
216+
self, name: str = "", id: str = "", image: str = ""
217+
) -> FullUserResponse:
216218
"""
217219
Creates or updates users. This method performs an "upsert" operation,
218220
where it checks if each user already exists and updates their information
219221
if they do, or creates a new user entry if they do not.
220222
"""
221-
user = UserRequest(name=name, id=id)
223+
id = id or str(uuid4())
224+
user = UserRequest(name=name, id=id, image=image)
222225
users_map = {user.id: user}
223226
response = await self.update_users(users_map)
224227
user = response.data.users[user.id]
@@ -328,13 +331,16 @@ def feeds(self) -> FeedsClient:
328331
)
329332

330333
@telemetry.operation_name("getstream.api.common.create_user")
331-
def create_user(self, name: str = "", id: str = str(uuid4()), image=""):
334+
def create_user(
335+
self, name: str = "", id: str = "", image: str = ""
336+
) -> FullUserResponse:
332337
"""
333338
Creates or updates users. This method performs an "upsert" operation,
334339
where it checks if each user already exists and updates their information
335340
if they do, or creates a new user entry if they do not.
336341
"""
337-
user = UserRequest(name=name, id=id)
342+
id = id or str(uuid4())
343+
user = UserRequest(name=name, id=id, image=image)
338344
users_map = {user.id: user}
339345
response = self.update_users(users_map)
340346
user = response.data.users[user.id]

0 commit comments

Comments
 (0)