Skip to content

NODE_CLASS is overwritten when using a custom SchemaBuilder #65

@bvanelli

Description

@bvanelli

First of all, I know that this is not the situation to open this issue, but I came across a situation where I wanted to provide a custom NODE_CLASS to the GenSON Schema parser. Let's simplify:

class ExampleNode(SchemaNode):
    def add_object(self, obj):
        super().add_object(obj)
        print("Hello world")

class ExampleSchemaBuilder(SchemaBuilder):
    NODE_CLASS = ExampleNode

I noticed that the print wasn't called at all. Digging deeper, the reason for it is that the meta-class directly references the class SchemaNode, while it should instead use cls.NODE_CLASS.

cls.NODE_CLASS = type('%sSchemaNode' % name, (SchemaNode,),
{'STRATEGIES': cls.STRATEGIES})

Replacing it by cls.NODE_CLASS instead of SchemaNode for the base class solves the issue.

I'm willing to contribute the change if you think this is a relevant issue.

Have a great day!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions