Opened 8 years ago

Closed 8 years ago

#15066 closed defect (fixed)

Pymongo breaks displayhook _graphics_()

Reported by: vbraun Owned by:
Priority: major Milestone: sage-5.12
Component: graphics Keywords:
Cc: cremona Merged in: sage-5.12.beta4
Authors: Volker Braun Reviewers: John Cremona
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: #14469 Stopgaps:

Status badges


Apparently pymongo uses a getattr hack that claims to have all and every method implemented, and then fails flat on its face when you actually try. This breaks the new displayhook.

Note that this error will just appear if you (implicitly) call the displayhook. Pymongo is working just fine, only the implicit printing is broken:

sage: import pymongo 
sage: c = pymongo.Connection()
sage: c.__repr__()
"Connection('localhost', 27017)"
sage: c
TypeError                                 Traceback (most recent call last)
<ipython-input-4-2cd6ee2c70b0> in <module>()
----> 1 c

/home/vbraun/opt/sage-5.12.beta0/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in __call__(self, result)
    236             self.start_displayhook()
    237             self.write_output_prompt()
--> 238             format_dict = self.compute_format_data(result)
    239             self.write_format_data(format_dict)
    240             self.update_user_ns(result)

/home/vbraun/opt/sage-5.12.beta0/local/lib/python2.7/site-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
    148             MIME type representation of the object.
    149         """
--> 150         return
    152     def write_format_data(self, format_dict):

/home/vbraun/opt/sage-5.12.beta0/local/lib/python2.7/site-packages/IPython/core/formatters.pyc in format(self, obj, include, exclude)
    124                     continue
    125             try:
--> 126                 data = formatter(obj)
    127             except:
    128                 # FIXME: log the exception

/home/vbraun/opt/sage-5.12.beta0/local/lib/python2.7/site-packages/sage/misc/displayhook.pyc in __call__(self, obj)
    310         """
    311         if hasattr(obj, '_graphics_') and not isinstance(obj, type):
--> 312             if obj._graphics_():
    313                 return ''
    314         s = self._format_obj(obj)

/home/vbraun/opt/sage-5.12.beta0/local/lib/python2.7/site-packages/pymongo-2.6-py2.7-linux-x86_64.egg/pymongo/database.pyc in __call__(self, *args, **kwargs)
    811                         "call the '%s' method on a '%s' object it is "
    812                         "failing because no such method exists." % (
--> 813                             self.__name, self.__connection.__class__.__name__))

TypeError: 'Database' object is not callable. If you meant to call the '_graphics_' method on a 'Connection' object it is failing because no such method exists.

Attachments (1)

trac_15066_pymongo_displayhook.patch (1.4 KB) - added by vbraun 8 years ago.
Updated patch

Download all attachments as: .zip

Change History (9)

comment:1 follow-up: Changed 8 years ago by ppurka

Where do you get pymongo from? It is not in standard packages and it is not even in optional packages.

comment:2 in reply to: ↑ 1 Changed 8 years ago by cremona

Replying to ppurka:

Where do you get pymongo from? It is not in standard packages and it is not even in optional packages.

You get it like this:

sage -sh
<different prompt> easy_install -U pymongo

I am using it for a project which uses Sage as a backend to a big number theory database, see and the readme at .

comment:3 Changed 8 years ago by cremona

Sorry, the initial patch does not work for me (but I know that you have not marked the ticket as needs_review).

Changed 8 years ago by vbraun

Updated patch

comment:4 Changed 8 years ago by vbraun

I had only changed the doctest but not the interactive displayhook... my bad. I will set this to "needs review" once tests pass ;-)

Last edited 8 years ago by vbraun (previous) (diff)

comment:5 Changed 8 years ago by cremona

With the new patch all tests pass for me: both my manual test with pymongo, and a full test of the whole library.

Note to Release Manager: it is OK not to have a doctest showing that the problem is fixed since the original problem only arises when pymongo has been installed and the machine has a running mongo daemon. I was the original reporter, and "it works for me".

As soon as Volker sets the tciket to "needs review" I'll give it a positive review.

comment:6 Changed 8 years ago by vbraun

  • Authors set to Volker Braun
  • Reviewers set to John Cremona
  • Status changed from new to needs_review

Tests pass for me, too

comment:7 Changed 8 years ago by cremona

  • Status changed from needs_review to positive_review

comment:8 Changed 8 years ago by jdemeyer

  • Merged in set to sage-5.12.beta4
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.