From 7763b4b595f0ba5a2279ae8593fbf4141c686ed8 Mon Sep 17 00:00:00 2001 From: liujian8670 <10318920+liujian8670@user.noreply.gitee.com> Date: Sun, 23 Apr 2023 04:07:01 +0000 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=B0=E5=BB=BA=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E6=B2=A1=E6=9C=89=E5=85=B3=E8=81=94=E8=A7=92=E8=89=B2?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=BC=9A=E5=85=B3=E8=81=94=E6=89=80=E6=9C=89?= =?UTF-8?q?=E8=A7=92=E8=89=B2BUG=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liujian8670 <10318920+liujian8670@user.noreply.gitee.com> --- kinit-api/apps/vadmin/auth/crud.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kinit-api/apps/vadmin/auth/crud.py b/kinit-api/apps/vadmin/auth/crud.py index 801296c..7b19de5 100644 --- a/kinit-api/apps/vadmin/auth/crud.py +++ b/kinit-api/apps/vadmin/auth/crud.py @@ -63,9 +63,10 @@ class UserDal(DalBase): data.password = self.model.get_password_hash(password) data.avatar = data.avatar if data.avatar else settings.DEFAULT_AVATAR obj = self.model(**data.dict(exclude={'role_ids'})) - roles = await RoleDal(self.db).get_datas(limit=0, id=("in", data.role_ids), v_return_objs=True) - for role in roles: - obj.roles.append(role) + if data.role_ids: + roles = await RoleDal(self.db).get_datas(limit=0, id=("in", data.role_ids), v_return_objs=True) + for role in roles: + obj.roles.append(role) await self.flush(obj) return await self.out_dict(obj, v_options, v_return_obj, v_schema)