Skip to content

Commit

Permalink
fixing excess fields on DocumentStep
Browse files Browse the repository at this point in the history
  • Loading branch information
alexviquez committed Jan 24, 2024
1 parent 001eec7 commit 428f863
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion mati/resources/verifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def __post_init__(self):
]
for doc in self.documents:
doc['steps'] = [
VerificationDocumentStep(**step) for step in doc['steps']
VerificationDocumentStep._from_dict(step)
for step in doc['steps']
]
docs.append(VerificationDocument(**doc))
self.documents = docs
Expand Down
17 changes: 15 additions & 2 deletions mati/types/enums.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dataclasses import dataclass, field
from dataclasses import dataclass, field, fields
from enum import Enum
from typing import BinaryIO, Dict, List, Optional, Union
from typing import Any, BinaryIO, Dict, List, Optional, Union


class SerializableEnum(str, Enum):
Expand Down Expand Up @@ -34,6 +34,19 @@ class VerificationDocumentStep:
error: Optional[Dict] = None
data: Optional[Dict] = field(default_factory=dict)

@classmethod
def _filter_excess_fields(cls, obj_dict: Dict) -> None:
excess = set(obj_dict.keys()) - {f.name for f in fields(cls)}
for f in excess:
del obj_dict[f]

@classmethod
def _from_dict(
cls, obj_dict: Dict[str, Any]
) -> 'VerificationDocumentStep':
cls._filter_excess_fields(obj_dict)
return cls(**obj_dict)


@dataclass
class Errors:
Expand Down
2 changes: 1 addition & 1 deletion mati/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.0.4' # pragma: no cover
__version__ = '2.0.5.dev0' # pragma: no cover
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ interactions:
"steps": [{"status": 200, "id": "document-reading", "data": {"fullName": {"required":
true, "label": "Name", "value": "FIRST NAME"}, "address": {"label": "Address",
"value": "Varsovia 36, 06600 CDMX"}, "emissionDate": {"format": "date", "label":
"Emission Date", "value": "1880-01-01"}}, "error": null}, {"status": 200,
"Emission Date", "value": "1880-01-01"}}, "error": null, "reused": false, "cacheHit": false}, {"status": 200,
"id": "watchlists", "error": null}], "fields": {"address": {"value": "Varsovia
36, 06600 CDMX"}, "emissionDate": {"value": "1880-01-01"}, "fullName": {"value":
"FIRST LASTNAME"}}, "photos": ["https://media.getmati.com/file?location=xyc"]}],
Expand Down

0 comments on commit 428f863

Please sign in to comment.