Fix updating instance with sqlalchemy core

This commit is contained in:
Tulir Asokan 2019-09-01 15:07:09 +03:00
parent 4d7fa10382
commit bbbb92782f
3 changed files with 17 additions and 16 deletions

View file

@ -85,13 +85,14 @@ async def _update_client(client: Client, data: dict) -> web.Response:
return resp.bad_client_connection_details
except ValueError as e:
return resp.mxid_mismatch(str(e)[len("MXID mismatch: "):])
await client.update_avatar_url(data.get("avatar_url", None))
await client.update_displayname(data.get("displayname", None))
await client.update_started(data.get("started", None))
client.enabled = data.get("enabled", client.enabled)
client.autojoin = data.get("autojoin", client.autojoin)
client.sync = data.get("sync", client.sync)
return resp.updated(client.to_dict())
with client.db_instance.edit_mode():
await client.update_avatar_url(data.get("avatar_url", None))
await client.update_displayname(data.get("displayname", None))
await client.update_started(data.get("started", None))
client.enabled = data.get("enabled", client.enabled)
client.autojoin = data.get("autojoin", client.autojoin)
client.sync = data.get("sync", client.sync)
return resp.updated(client.to_dict())
@routes.post("/client/new")

View file

@ -64,13 +64,13 @@ async def _create_instance(instance_id: str, data: dict) -> web.Response:
async def _update_instance(instance: PluginInstance, data: dict) -> web.Response:
if not await instance.update_primary_user(data.get("primary_user", None)):
return resp.primary_user_not_found
instance.update_id(data.get("id", None))
instance.update_enabled(data.get("enabled", None))
instance.update_config(data.get("config", None))
await instance.update_started(data.get("started", None))
await instance.update_type(data.get("type", None))
instance.db.commit()
return resp.updated(instance.to_dict())
with instance.db_instance.edit_mode():
instance.update_id(data.get("id", None))
instance.update_enabled(data.get("enabled", None))
instance.update_config(data.get("config", None))
await instance.update_started(data.get("started", None))
await instance.update_type(data.get("type", None))
return resp.updated(instance.to_dict())
@routes.put("/instance/{id}")
@ -90,7 +90,7 @@ async def update_instance(request: web.Request) -> web.Response:
@routes.delete("/instance/{id}")
async def delete_instance(request: web.Request) -> web.Response:
instance_id = request.match_info.get("id", "").lower()
instance = PluginInstance.get(instance_id, None)
instance = PluginInstance.get(instance_id)
if not instance:
return resp.instance_not_found
if instance.started:

View file

@ -21,7 +21,7 @@ setuptools.setup(
packages=setuptools.find_packages(),
install_requires=[
"mautrix>=0.4.dev67,<0.5",
"mautrix>=0.4.dev68,<0.5",
"aiohttp>=3.0.1,<4",
"SQLAlchemy>=1.2.3,<2",
"alembic>=1.0.0,<2",