get_db() being called in QuerySetManager

50 views
Skip to first unread message

sunil arora

unread,
Feb 13, 2012, 1:26:21 AM2/13/12
to mongoen...@googlegroups.com, mongoeng...@googlegroups.com
Hi,

We need a quick help to resolve a critical issue.

We are using 0.4 version of mongoengine. We will be updating to latest version, but that is a couple of weeks away.

We are facing a weird situation about DB connectivity. 

Very recently we started using inheritance in our models. For ex.

Class A(Document): pass

Class B(A): pass

Class C(A): pass

With introduction of such classes, we are seeing _get_db() function is being invoked on import of our B, C classes.

I traced further and found that in TopLevelDocumentMetaClass's new method, where QuerySetManager is being instantiated and in turn descriptor __get__ is being called which is making _get_db() call.

Reason we have a problem with _get_db() being invoked during importing of our modules, it creates a db connection with with default settings which are "localhost:27017", which we want to avoid because we are reusing the same connection.

We want connection to be made on explicit call instead during the imports.

I did some digging in 0.5 code and it has changed significantly in those areas where QuerySetManger is being defined.

Thanks
Sunil

Ross Lawley

unread,
Feb 13, 2012, 4:35:35 AM2/13/12
to mongoen...@googlegroups.com
Hi Sunil,

Unfortunately, that is the case with 0.4 in 0.5 we refactored how document / collections were initially setup and how we deal with creating capped collections etc.

Creating the connection before importing document models will stop mongoengine using its default connection settings.

Ross

sunil arora

unread,
Feb 13, 2012, 6:02:07 AM2/13/12
to mongoen...@googlegroups.com
Hi Ross,

Thanks for the quick reply.

If we have to upgrade from 0.4 to 0.5, what are key points that we should keep in mind.  Any breaking changes that we need to be aware about ?

Thanks
Sunil

Ross Lawley

unread,
Feb 13, 2012, 6:21:36 AM2/13/12
to mongoen...@googlegroups.com
Hi Sunil,

There are a number of relatively minor upgrade steps - http://mongoengine.org/docs/v0.5/upgrade.html?highlight=upgrade#to-0-5

As always, test first!

Ross

sunil arora

unread,
Feb 13, 2012, 6:46:50 AM2/13/12
to mongoen...@googlegroups.com
Thanks for the pointer Ross!
Reply all
Reply to author
Forward
0 new messages