Jaymon / prom

A PostgreSQL or SQLite orm for Python
MIT License
22 stars 4 forks source link

Testdata dispatch should check parents before falling back to the default method #182

Closed Jaymon closed 5 months ago

Jaymon commented 5 months ago

Let's say I had something like this:


class Parent(Orm):
    pass

class Child(Parent):
    pass

Now, I create a custom testdata method:


class ModelData(prom.extras.testdata.ModelData):
    def get_parent_fields(self, **kwargs):
        return self.get_orm_fields(**kwargs)

Now, what happens when I call this from my test method?

c = self.get_child()

It resolves the methods like this:

But I would like it to resolve the method like this:

This should actually be pretty easy to do, I just need to modify prom.extras.testdata.ModelData._dispatch_method to grab all the parents and check them also before falling back to the passed in default method.

Jaymon commented 5 months ago

Turns out this is a bit more complicated than I originally expected. I need to update both the internal dispatch but also the getattribute dispatch (_parse_method_name), this is how I'm thinking to solve it: