Skip to content

Commit

Permalink
✨ Fix issues where array was null in Harambe
Browse files Browse the repository at this point in the history
  • Loading branch information
asim-shrestha committed Jun 20, 2024
1 parent 4e79087 commit 3b7f787
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions harambe/parser/parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from abc import ABC, abstractmethod
from pydantic import BaseModel, create_model, Extra, Field, NameEmail, ValidationError
from typing import Any, Dict, List, Optional, Type

from pydantic import BaseModel, create_model, Extra, Field, NameEmail, ValidationError

from harambe.parser.type_date import ParserTypeDate
from harambe.parser.type_enum import ParserTypeEnum
from harambe.parser.type_phone_number import ParserTypePhoneNumber
Expand Down Expand Up @@ -79,6 +80,8 @@ def _items_schema_to_python_type(
Convert a JSON schema's items property to a Python type
"""
item_type = items_info.get("type")
if item_type is None:
raise ValueError(f"Item type for array `{model_name}` is missing")

if item_type == OBJECT_TYPE:
python_type = self._schema_to_pydantic_model(
Expand Down Expand Up @@ -116,14 +119,14 @@ def _schema_to_pydantic_model(

if field_type == OBJECT_TYPE:
python_type = self._schema_to_pydantic_model(
field_info.get("properties", {}),
field_info.get("properties", {}) or {},
model_name=f"{model_name}{field_name.capitalize()}",
)
elif field_type == LIST_TYPE:
# Lists can't be null
python_type = List[
self._items_schema_to_python_type(
field_info.get("items", {}),
field_info.get("items", {}) or {},
model_name=f"{model_name}Item",
)
]
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "harambe-sdk"
version = "0.13.4"
version = "0.13.5"
description = "Data extraction SDK for Playwright 🐒🍌"
authors = ["awtkns <[email protected]>"]
readme = "README.md"
Expand Down

0 comments on commit 3b7f787

Please sign in to comment.