closeio / flask-common

Some commonly shared code for Flask, MongoEngine, and Python apps
26 stars 4 forks source link

Allow passing a function that resolves into a QuerySet to MongoReference #53

Closed wojcikstefan closed 5 years ago

wojcikstefan commented 5 years ago

This code allows you to do either:

  1. MongoReference(..., queryset=SomeDoc.objects) (the old way)
  2. MongoReference(..., queryset=lambda: SomeDoc.objects)

This new way allows you to pass in a custom queryset w/o triggering a MongoDB connection (which isestablished automatically as soon as SomeDoc.objects is called, at least for auth'd connections).

See https://github.com/closeio/closeio/issues/16338 for details.

tsx commented 5 years ago

Confirmed it runs without connecting to mongo in my test setup. 👍