swish-python icon indicating copy to clipboard operation
swish-python copied to clipboard

Add missing parameter causing DataError on get_refund

Open HeyHugo opened this issue 4 years ago • 2 comments

Add missing parameter callbackIdentifier which is causing DataError on GET /refund/{id}

Sometime between May 19 and 20 swish api (in production) added callbackIdentifier to the response which is not present on the model.

site-packages/swish/client.py in get_refund(self, refund_id)
     79         response = self.get('refunds/' + refund_id)
     80         response.raise_for_status()
---> 81         return Refund(response.json())

site-packages/schematics/models.py in __init__(self, raw_data, trusted_data, deserialize_mapping, init, partial, strict, validate, app_data, lazy, **kwargs)
    233             trusted_data=trusted_data, mapping=deserialize_mapping,
    234             partial=partial, strict=strict, validate=validate, new=True,
--> 235             app_data=app_data, **kwargs)
    236         self._data.converted = data
    237         if validate:

site-packages/schematics/models.py in _convert(self, raw_data, context, **kwargs)
    297         should_validate = getattr(context, 'validate', kwargs.get('validate', False))
    298         func = validate if should_validate else convert
--> 299         return func(self._schema, self, raw_data=raw_data, oo=True, context=context, **kwargs)
    300
    301     def export(self, field_converter=None, role=None, app_data=None, **kwargs):

site-packages/schematics/transforms.py in convert(cls, mutable, raw_data, **kwargs)
    426
    427 def convert(cls, mutable, raw_data=None, **kwargs):
--> 428     return import_loop(cls, mutable, raw_data, import_converter, **kwargs)
    429
    430

site-packages/schematics/transforms.py in import_loop(schema, mutable, raw_data, field_converter, trusted_data, mapping, partial, strict, init_values, apply_defaults, convert, validate, new, oo, recursive, app_data, context)
    172
    173     if errors:
--> 174         raise DataError(errors, data)
    175
    176     data = context.field_converter.post(schema, data, context)

DataError: {"callbackIdentifier": "Rogue field"}

HeyHugo avatar Jun 02 '21 11:06 HeyHugo

Hi! Will the pull request be merged or is this not the right way to fix it? I have trouble with exactly this and it would be great to have this merged and released. Cheers!

chrisbloecker avatar Nov 19 '21 06:11 chrisbloecker

@chrisbloecker It does indeed fix the issue. Been running on my fork since the fix :)

You can fork it yourself and add to your dependencies or depend on mine until it is merged: pip install https://github.com/HeyHugo/swish-python/archive/55497af1c28c1a58261daf167c5ede9668921e2e.zip

HeyHugo avatar Nov 19 '21 14:11 HeyHugo