rbw / aiosnow

Asynchronous ServiceNow Library
MIT License
73 stars 12 forks source link

When calling .update() on a custom table response raises keyerror #90

Closed michaeldcanady closed 3 years ago

michaeldcanady commented 3 years ago

method:

async def addWorkNotes(client,CSNumber,notes):
    async with CSTable(client, table_name="u_computer_support") as CS:
        response = await CS.update(
            CSTable.number == CSNumber,
            dict(
                work_notes = notes
                )
            )
        print("Updated work_notes: {}".format(response["work_notes"]))

error: Traceback (most recent call last): File "D:/Projects/PySource/CloserTest/aiosnowTest.py", line 36, in asyncio.run(main()) File "C:\Users\dmcanady\AppData\Local\Programs\Python\Python38-32\lib\asyncio\runners.py", line 43, in run return loop.run_until_complete(main) File "C:\Users\dmcanady\AppData\Local\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 616, in run_until_complete return future.result() File "D:/Projects/PySource/CloserTest/aiosnowTest.py", line 13, in main await addWorkNotes(client,CSNumber,"I WORK!") File "D:/Projects/PySource/CloserTest/aiosnowTest.py", line 27, in addWorkNotes response = await CS.update( File "C:\Users\dmcanady\AppData\Local\Programs\Python\Python38-32\lib\site-packages\aiosnow\models\table\model.py", line 166, in update sys_id = await self.get_object_id(selection) File "C:\Users\dmcanady\AppData\Local\Programs\Python\Python38-32\lib\site-packages\aiosnow\models\table\model.py", line 147, in get_object_id return record.dict[self._primary_key] KeyError: <property object at 0x04B16CD0>

rbw commented 3 years ago

Which version are you using?

This should be fixed with https://github.com/rbw/aiosnow/commit/f76648ec259d27218f0ebd469bac9882a5d19cbc, which is included in the latest version on PyPI (0.5.1).

michaeldcanady commented 3 years ago

I feel dumb lol. When I installed it, it must have grabbed a previous version. Now my error is aiosnow.exceptions.SchemaError: The targeted "<class 'CustomerSupport.CSTable'>" cannot be queried: its schema lacks a field with "is_primary" set

table code is:

class CSTable(TableModel):
    sys_id = fields.String(primary_key=True)
    description = fields.String()
    opened_by = fields.String()
    number = fields.String()
    impact = fields.IntegerMap()
    priority = fields.Integer()
    assignment_group = fields.StringMap()
    sys_created_on = fields.DateTime()
    made_sla = fields.Boolean()
    work_notes = fields.String()
    work_notes_list = fields.String()
    opened_by = fields.String()
    assigned_to = fields.String()
    technician = fields.String()
rbw commented 3 years ago

It should be is_primary, not primary_key. This was incorrectly documented in usage.model.declare. Corrected with 99e057da9d6f2677a92805b41ac436d05355b9c8.