Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Can't do subqueries with queries on different DBs. #20

Open
erwinfeser opened this issue Feb 21, 2015 · 1 comment
Open
Milestone

Comments

@erwinfeser
Copy link

It happens when I try to save an object related to other objects, even if other objects were fetched from the same database that I am using to write.

/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.pyc in create(self, **kwargs)
    320         obj = self.model(**kwargs)
    321         self._for_write = True
--> 322         obj.save(force_insert=True, using=self.db)
    323         return obj
    324 

/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.pyc in save(self, force_insert, force_update, using, update_fields)
    543 
    544         self.save_base(using=using, force_insert=force_insert,
--> 545                        force_update=force_update, update_fields=update_fields)
    546     save.alters_data = True
    547 

/app/.heroku/python/lib/python2.7/site-packages/django/db/models/base.pyc in save_base(self, raw, force_insert, force_update, using, update_fields)
    580         if not meta.auto_created:
    581             signals.post_save.send(sender=origin, instance=self, created=(not updated),
--> 582                                    update_fields=update_fields, raw=raw, using=using)
    583 
    584     save_base.alters_data = True

/app/.heroku/python/lib/python2.7/site-packages/django/dispatch/dispatcher.pyc in send(self, sender, **named)
    183 
    184         for receiver in self._live_receivers(sender):
--> 185             response = receiver(signal=self, sender=sender, **named)
    186             responses.append((receiver, response))
    187         return responses

/app/apps/grains/signals.py in update_answered_questions_num(sender, **kwargs)
    241     instance = kwargs.get('instance')
    242     if instance:
--> 243         instance.profile.answered_questions_num = instance.profile.get_answered_questions().count()
    244         instance.profile.save(update_fields=['answered_questions_num'])
    245 

/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.pyc in count(self)
    292             return len(self._result_cache)
    293 
--> 294         return self.query.get_count(using=self.db)
    295 
    296     def get(self, *args, **kwargs):

/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/query.pyc in get_count(self, using)
    388 
    389         obj.add_count_column()
--> 390         number = obj.get_aggregation(using=using)[None]
    391 
    392         # Apply offset and limit constraints manually, since using LIMIT/OFFSET

/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/query.pyc in get_aggregation(self, using)
    354         query.related_select_cols = []
    355 
--> 356         result = query.get_compiler(using).execute_sql(SINGLE)
    357         if result is None:
    358             result = [None for q in query.aggregate_select.items()]

/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py in execute_sql(self, result_type)
    774         
    775         try:
--> 776             sql, params = self.as_sql()
    777             if not sql:
    778                 raise EmptyResultSet

/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py in as_sql(self, with_limits, with_col_aliases)
     92         qn = self.quote_name_unless_alias
     93 
---> 94         where, w_params = self.query.where.as_sql(qn=qn, connection=self.connection)
     95         having, h_params = self.query.having.as_sql(qn=qn, connection=self.connection)
     96         having_group_by = self.query.having.get_cols()

/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/where.pyc in as_sql(self, qn, connection)
    101             try:
    102                 if hasattr(child, 'as_sql'):
--> 103                     sql, params = child.as_sql(qn=qn, connection=connection)
    104                 else:
    105                     # A leaf node in the tree.

/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/where.pyc in as_sql(self, qn, connection)
    399         if hasattr(query, 'values'):
    400             if query._db and connection.alias != query._db:
--> 401                 raise ValueError("Can't do subqueries with queries on different DBs.")
    402             # Do not override already existing values.
    403             if not hasattr(query, 'field_names'):

ValueError: Can't do subqueries with queries on different DBs.
@jsocol
Copy link
Collaborator

jsocol commented Feb 21, 2015

Can you show us an example of the code that threw the error? The traceback will be a lot more helpful with some context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants