Skip to content

Commit

Permalink
HDXDSYS-1128 Fix wfp commodity database export failure (#180)
Browse files Browse the repository at this point in the history
* Fix WFP commodity failure

* Add changelog
  • Loading branch information
mcarans authored Oct 7, 2024
1 parent 05aab02 commit 0b5781f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [0.10.4] - 2024-10-07
## [0.10.5] - 2024-10-08

### Fixed

- Fix broken database export
- WFP commodity normalised and fuzzy matching

## [0.10.4] - 2024-10-08

### Fixed

Expand Down
10 changes: 9 additions & 1 deletion src/hapi/pipelines/database/wfp_commodity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from hapi_schema.db_wfp_commodity import DBWFPCommodity
from hapi_schema.utils.enums import CommodityCategory
from hdx.scraper.framework.utilities.reader import Read
from hdx.utilities.text import normalise
from sqlalchemy.orm import Session

from ..utilities.mappings import get_code_from_name
from .base_uploader import BaseUploader

logger = getLogger(__name__)
Expand All @@ -22,6 +24,7 @@ def __init__(
super().__init__(session)
self._datasetinfo = datasetinfo
self.data = {}
self.unmatched = []

def populate(self) -> None:
logger.info("Populating WFP commodity table")
Expand All @@ -38,8 +41,13 @@ def populate(self) -> None:
)
self.data[name] = code
self.data[code] = name
self.data[normalise(name)] = code
self._session.add(commodity_row)
self._session.commit()

def get_commodity_code(self, commodity: str) -> Optional[str]:
return self.data.get(commodity)
return get_code_from_name(
name=commodity,
code_lookup=self.data,
unmatched=self.unmatched,
)

0 comments on commit 0b5781f

Please sign in to comment.