You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Traceback (most recent call last):
File "switch.py", line 24, in <module>
loop.run_until_complete(switch(args.trigger_id))
File "/usr/lib/python3.6/asyncio/base_events.py", line 473, in run_until_complete
return future.result()
File "switch.py", line 8, in switch
trigger = await Trigger.objects.get(pk=trigger_id)
File "/home/foxmask/DjangoVirtualEnv/yeoboseyo/lib/python3.6/site-packages/orm/models.py", line 182, in get
return await self.filter(**kwargs).get()
File "/home/foxmask/DjangoVirtualEnv/yeoboseyo/lib/python3.6/site-packages/orm/models.py", line 127, in filter
column = self.table.columns[key]
File "/home/foxmask/DjangoVirtualEnv/yeoboseyo/lib/python3.6/site-packages/sqlalchemy/util/_collections.py", line 194, in __getitem__
return self._data[key]
KeyError: 'pk'
switch.py
# coding: utf-8
import argparse
import asyncio
from yeoboseyo.models import Trigger
async def switch(trigger_id):
"""
:param trigger_id: trigger id to switch on/off
:return:
"""
trigger = await Trigger.objects.get(pk=trigger_id)
status = not trigger.status
await trigger.update(status=status)
print(f"Successfully switched Trigger '{trigger.description}' to {status}")
if __name__ == '__main__':
print('여보세요 ! Switch')
parser = argparse.ArgumentParser(description='Switch status of one trigger')
parser.add_argument('trigger_id',
metavar='N',
type=int,
help='provide the id of the trigger to switch on/off')
args = parser.parse_args()
loop = asyncio.get_event_loop()
loop.run_until_complete(switch(args.trigger_id))
loop.close()
I met the same problem as you.
The method model.objects.get if have arguments, it will use QuerySet's filter method.
I can't find any extra handle for pk in the filter method.
if the filter method's argument doesn't contain "__", it just returns self.table.columns[column_name].
I meet this error
switch.py
and the models
if I use
instead of the code above everything wokrs fine
The text was updated successfully, but these errors were encountered: