fix(CFT-223): Handle empty list to dict conversion for user_properties#23
Merged
fix(CFT-223): Handle empty list to dict conversion for user_properties#23
Conversation
The Keboola platform converts empty JSON objects {} to empty arrays []
in configuration parameters. This fix adds defensive programming to
handle this known platform behavior.
Changes:
- Add __post_init__ method to Configuration class to convert empty
lists to empty dicts for user_properties
- Update type hint to accept both dict and list types
- Add comprehensive test coverage for the fix
Co-Authored-By: david@keboola.com <esnerda@gmail.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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 the "eternal KBC bug" (CFT-223) where the Keboola platform converts empty JSON objects
{}to empty arrays[]in configuration parameters. When users leaveuser_propertiesempty, the platform preprocessing converts it from{}to[], but the Configuration dataclass expected a dictionary, causing dacite validation to throw aWrongTypeError.Changes:
user_propertiestype hint to accept bothdict[str, object] | listso dacite can deserialize either type__post_init__method to Configuration class that converts empty lists to empty dictsUserExceptionwith a clear error messageReview & Testing Checklist for Human
config.jsoncontains"user_properties": [], dacite.from_dict() in component.py correctly passes the list to the dataclass and__post_init__converts it to{}.user_propertiesin the UI and verify the component runs without theWrongTypeError._merge_user_parameters()(line 119-131 in component.py) receives a dict after the conversion.Recommended test plan:
runtime.tagconfigurationuser_propertiesNotes
{}to[]conversion is expected__post_init__as requestedLink to Devin run: https://app.devin.ai/sessions/0dcae42daa1342af93cdf52c06e42d6c
Requested by: david@keboola.com (@davidesner)