Skip to content

Validator: Fix casting record_specific_diffs object to list for json serialization#1275

Open
barbarahui wants to merge 1 commit intomainfrom
validation-fix-casting-object-to-list
Open

Validator: Fix casting record_specific_diffs object to list for json serialization#1275
barbarahui wants to merge 1 commit intomainfrom
validation-fix-casting-object-to-list

Conversation

@barbarahui
Copy link
Collaborator

@barbarahui barbarahui commented Mar 17, 2026

I'm a bit confused as to what exactly is going on here in terms of what type of object record_specific_diffs is (prior to any attempts to set its type to list). In case of collection 27566, it seems be an instance of dict. The set_encoder function clearly expects it to be of type set or SetOrdered, but I needed to add dict as an option.

The other problem was that calling set_encoder() as part of the json.dumps call (by adding the default=set_encoder argument) results in the obj being of type type (the type superclass). Calling set_encoder separately fixes this problem.

In reading through the code, it seems to me that record_specific_diffs is always a dict. However, if we don't explicitly cast it to a list by calling set_encoder on it, then calling json.dumps on it results in a "TypeError: Object of type type is not JSON serializable" error. So it is somehow both a dict and a type object? I'm deeply confused.

If the changes I've made here make sense, then we should probably change the name of the set_encoder function. All I can think of is diffs_obj_to_list.

@barbarahui barbarahui changed the title Fix casting record_specific_diffs object to list for json serialization Validator: Fix casting record_specific_diffs object to list for json serialization Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

validate_collection error TypeError: Object of type type is not JSON serializable for pastperfect.xml collections

3 participants