Skip to content

Call super().add_object() in List, Tuple and Object strategies#95

Open
gaoflow wants to merge 1 commit into
wolverdude:masterfrom
gaoflow:fix-add-object-super-chaining
Open

Call super().add_object() in List, Tuple and Object strategies#95
gaoflow wants to merge 1 commit into
wolverdude:masterfrom
gaoflow:fix-add-object-super-chaining

Conversation

@gaoflow

@gaoflow gaoflow commented Jul 7, 2026

Copy link
Copy Markdown

Problem

SchemaStrategy.add_object is a no-op base method, but cooperative subclasses
rely on each strategy's add_object override chaining up through
super().add_object() so their own hooks run. #79 restored this for Number
("added missing super in Number so inheritance would be called") and #82
applied it to the new Enum strategy — but List, Tuple and Object still
override add_object without calling super().

As a result, a cooperative mixin's add_object is silently skipped for arrays,
tuples and objects, while it runs for numbers and enums:

class RecordingMixin(SchemaStrategy):
    log = []
    def add_object(self, obj):
        type(self).log.append(obj)
        super().add_object(obj)

class RecordingObject(Object, RecordingMixin):
    log = []

class B(SchemaBuilder):
    STRATEGIES = (RecordingObject,)

B().add_object({})
# RecordingObject.log == []   -> hook never ran (should be [{}])

Fix

Add the missing super().add_object(obj) call to List, Tuple and Object,
matching Number and Enum. The base method is a no-op, so stock genson
behavior is unchanged; this only completes the cooperative chain for
subclasses.

Tests

TestAddObjectSuperChaining in test/test_custom.py records objects via a
cooperative mixin and asserts the hook fires for List, Tuple and Object
(with Number as the already-fixed control), plus a nested
object → list → object case verifying the hook fires at every level. The array/
tuple/object tests fail before the change and pass after; full suite: 118
passed.

The base SchemaStrategy.add_object is a no-op, but cooperative subclasses
rely on each strategy's add_object override chaining up through super()
so their hooks run. PR wolverdude#79 restored this for Number and PR wolverdude#82 applied it
to Enum, but List, Tuple and Object still overrode add_object without
calling super(), so a cooperative mixin's add_object was skipped for
arrays, tuples and objects. Add the missing super() calls.
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.

1 participant