elier
elier

Reputation: 459

Using PonyORM with Dependency Injector

PonyORM is a nice ORM implementation. Unfortunately, I haven't figure it out how to make it work with Dependency Injector library.

There are examples with the most important frameworks:
https://docs.ponyorm.org/integration_with_flask.html

From the DI perspective, I'm using a function initializer like this:
https://python-dependency-injector.ets-labs.org/providers/resource.html

def init_database(options):
    database = orm.Database(options)
    database.generate_mapping(create_tables=True)
    return database

class Container(containers.DeclarativeContainer):
    config = providers.Configuration()
    db = providers.Resource(init_database, config.database)

But I guess initialization is not happening at the right time, so entities are not yet bind:

pony.orm.core.ERDiagramError: Mapping is not generated for entity 'User'

My app works with PonyORM just fine. The error is really related to the introduction of the DI.

Upvotes: 0

Views: 37

Answers (0)

Related Questions