From 258a66476ad2edd7740353460372449aaef0b57b Mon Sep 17 00:00:00 2001 From: NewAgeAirbender <34139325+NewAgeAirbender@users.noreply.github.com> Date: Fri, 29 Mar 2024 16:00:17 -0500 Subject: [PATCH] Committee other_name working --- openstates/importers/base.py | 57 --------------------------- openstates/importers/organizations.py | 2 +- 2 files changed, 1 insertion(+), 58 deletions(-) diff --git a/openstates/importers/base.py b/openstates/importers/base.py index fee57b3d..a9778aa8 100644 --- a/openstates/importers/base.py +++ b/openstates/importers/base.py @@ -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)) diff --git a/openstates/importers/organizations.py b/openstates/importers/organizations.py index 58e99eb8..9a6557df 100644 --- a/openstates/importers/organizations.py +++ b/openstates/importers/organizations.py @@ -14,5 +14,5 @@ def limit_spec(self, spec: _JsonDict) -> _JsonDict: name = spec.pop("name", None) if name: - return Q(**spec) & (Q(name__iexact=name) | Q(other_names__name__iexact=name)) + return Q(**spec) & (Q(other_names__0__name=name) | Q(name=name)) return spec