Description
The register_generator function enforces the following check:
if not isinstance(generator_class, type) or not issubclass(
generator_class, BaseGenerator
):
raise TypeError(
f"Generator must inherit from BaseGenerator, got {generator_class}"
)
This logic incorrectly rejects subclasses of existing generators, even though those generators themselves ultimately derive from BaseGenerator.
As a result, extending an existing generator (as encouraged by the documentation) is not possible via register_generator.
To Reproduce
Use the example given at example/extend_builtin_generator.py or the following snippet:
from omymodels.models.sqlalchemy_v2 import ModelGenerator as SQLAlchemyV2Generator
from omymodels.plugins import register_generator
class SQLAlchemyV2Extension(SQLAlchemyV2Generator):
pass
register_generator(
name="sqlalchemy_v2_extension",
generator_class=SQLAlchemyV2Extension
)
Raises:
TypeError: Generator must inherit from BaseGenerator
Expected behavior
register_generator should accept subclasses of existing generators, as they already inherit (directly or indirectly) from BaseGenerator.
Workaround
Manually inject the generator:
from omymodels import plugins
plugins._custom_generators["sqlalchemy_v2_extension"] = SQLAlchemyV2Extension
Desktop:
- OS: Windows 11
- Python: 3.10
Description
The register_generator function enforces the following check:
This logic incorrectly rejects subclasses of existing generators, even though those generators themselves ultimately derive from BaseGenerator.
As a result, extending an existing generator (as encouraged by the documentation) is not possible via register_generator.
To Reproduce
Use the example given at
example/extend_builtin_generator.pyor the following snippet:Raises:
Expected behavior
register_generator should accept subclasses of existing generators, as they already inherit (directly or indirectly) from BaseGenerator.
Workaround
Manually inject the generator:
Desktop: