kvesteri / sqlalchemy-continuum

Versioning extension for SQLAlchemy.
BSD 3-Clause "New" or "Revised" License
580 stars 126 forks source link

sqlalchemy_continuum.model_builder class names don't include module #87

Open jpaul6 opened 9 years ago

jpaul6 commented 9 years ago

Hi there, I've got a sqlalchemy-continuum project for which I've got a large number of classes (derived from a small set of base classes/tables using polymorphic_identity). As it turns out, some of my classes have the same name, but are in different modules. This causes a problem with the classes built by continuum. For example, suppose I've got module/classes a.b.Foo and a.c.Foo. Then continuum attempts to build sqlalchemy_continuum.model_builder.Foo twice (and gives a warning) rather than building sqlalchemy_continuum.model_builder.a_b_Foo and sqlalchemy_continuum.model_builder.a_c_Foo.

The responsible code is at model_builder.py:250.

If it seems reasonable, I'd happily test and submit a pull request for a change that addresses this.

kvesteri commented 9 years ago

I think the warning is emitted from the SQLAlchemy side. SQLAlchemy's class registry uses string keys if I reckon correctly. How would you solve this issue?

kyheo commented 8 years ago

I had the same issue and id this quick workaround to solve the issue in model_bulder.py:255

        # Use full module name to avoid name collisions
        name = '{}{}Version'.format(
            self.model.__module__.title().replace('.', ''),
            self.model.__name__)
        return type(name, self.base_classes(), args)

I'll create a pull request later, once I'm confident this doesn't beak anything else.