Fix: Census field appends not included in response#13
Merged
Conversation
Add test case to verify that all census year fields (census2010, census2020, census2023, census2024) are properly parsed and included in the response. This test currently demonstrates the bug where census2024 and other years beyond 2023 are not being parsed even though the API returns them. Relates to #12
Replace hardcoded census year parsing (census2010, census2020, census2023) with dynamic detection and parsing of any census field returned by the API. Changes: - Modified _parse_fields() to automatically detect and parse any field matching the pattern "census" + digits (e.g., census2024, census2025) - Removed slots=True from GeocodioFields to allow dynamic field passing via **kwargs (backwards compatible, negligible performance impact) - Only parses census fields that are defined in the GeocodioFields model Benefits: - Fixes issue where census2024 was not being parsed - Future-proof: new census years only require adding a field definition to GeocodioFields, no changes needed to parsing logic - Maintains backwards compatibility with all existing census fields Fixes #12
|
@MiniCodeMonkey do we know how many users were impacted by this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #12 - Census field appends (like
census2024) were not being included in geocoding responses even though the raw JSON from the API included them.Problem
The
_parse_fields()method was hardcoding only three census years:census2010census2020census2023When users requested
census2024or any other census year, the data was returned by the API but not parsed into the response object.Solution
Implemented dynamic census field parsing:
Dynamic Detection: The parser now automatically detects any field matching the pattern
census+ digits (e.g.,census2024,census2025)Smart Filtering: Only parses census fields that are defined in the
GeocodioFieldsmodel to maintain type safetyFuture-Proof: Adding support for new census years only requires adding a single line to the
GeocodioFieldsdataclass - no changes to parsing logic neededChanges
src/geocodio/client.py: Replaced hardcoded census parsing with dynamic detectionsrc/geocodio/models.py: Removedslots=TruefromGeocodioFieldsto allow dynamic field passing (backwards compatible)tests/unit/test_geocode.pyto verify all census fields are parsedBackwards Compatibility
✅ No breaking changes
slots=Truehas negligible performance/memory impact (~56 bytes per instance)Testing
Example Usage