Skip to content

Commit

Permalink
Merge pull request #126 from openstates/rj_updates
Browse files Browse the repository at this point in the history
Update Org Importer
  • Loading branch information
NewAgeAirbender authored Mar 29, 2024
2 parents 37fe9c6 + 258a664 commit 60a51c7
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 60 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## 6.18.5 - March 29, 2024

* other_name in committee matching
* swap getargspec for getfullargspec on Update

## 6.18.4 - March 25, 2024

* Rollback on committee matching
Expand Down
2 changes: 1 addition & 1 deletion openstates/cli/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def do_scrape(
for scraper_name, scrape_args in scrapers.items():
ScraperCls = juris.scrapers[scraper_name]
if (
"session" in inspect.getargspec(ScraperCls.scrape).args
"session" in inspect.getfullargspec(ScraperCls.scrape).args
and "session" not in scrape_args
):
logger.warning(
Expand Down
57 changes: 0 additions & 57 deletions openstates/importers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,60 +593,3 @@ def resolve_person(

# return the newly-cached object
return self.person_cache[cache_key]

def resolve_committee(
self, json_id: str, allow_no_match: bool = False
) -> typing.Optional[_ID]:
if not json_id:
return None

if json_id.startswith("~"):
# keep caches of all the pseudo-ids to avoid doing 1000s of lookups during import
if json_id not in self.pseudo_id_cache:
spec = get_pseudo_id(json_id)
# need to include other_names in matching
if list(spec.keys()) == ["name"]:
name = spec["name"]
spec = (
Q(name__iexact=name)
| Q(other_names__name__iexact=name)
)
else:
spec = Q(**spec)

# continue with logic from resolve_json_id
if isinstance(spec, Q):
objects = self.model_class.objects.filter(spec)
else:
objects = self.model_class.objects.filter(**spec)
ids = {each.id for each in objects}
if len(ids) == 1:
self.pseudo_id_cache[json_id] = ids.pop()
errmsg = None
elif not ids:
errmsg = "cannot resolve pseudo id to {}: {}".format(
self.model_class.__name__, json_id
)
else:
errmsg = "multiple objects returned for {} pseudo id {}: {}".format(
self.model_class.__name__, json_id, ids
)

# either raise or log error
if errmsg:
if not allow_no_match:
raise UnresolvedIdError(errmsg)
else:
self.error(errmsg)
self.pseudo_id_cache[json_id] = None

# return the cached object
return self.pseudo_id_cache[json_id]

# get the id that the duplicate points to, or use self
json_id = self.duplicates.get(json_id, json_id)

try:
return self.json_to_db_id[json_id]
except KeyError:
raise UnresolvedIdError("cannot resolve id: {}".format(json_id))
2 changes: 1 addition & 1 deletion openstates/importers/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ def limit_spec(self, spec: _JsonDict) -> _JsonDict:

name = spec.pop("name", None)
if name:
return Q(**spec) & Q(name=name)
return Q(**spec) & (Q(other_names__0__name=name) | Q(name=name))
return spec
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 = "openstates"
version = "6.18.4"
version = "6.18.5"
description = "core infrastructure for the openstates project"
authors = ["James Turk <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 60a51c7

Please sign in to comment.