Report pages crash under psycopg2 >= 2.5

Bug #1233093 reported by Ole Martin Bjørndalen
14
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Network Administration Visualized
Fix Released
Medium
Morten Brekkevold

Bug Description

To reproduce, go to /report/room and click on any location:

    TypeError at /report/location
    function takes at most 2 arguments (3 given)

The reason is that QuotedString in psycopg2 2.5 no longer the character encoding parameter. To fix, change this in /usr/local/nav/lib/python/db/__init__.py:

    def escape(string):
        return str(psycopg2.extensions.QuotedString(string, "UTF8"))

to this:

    def escape(string):
        return str(psycopg2.extensions.QuotedString(string))

This change has no side effects. (The string will be encoded as UTF-8 no matter how you call the function.)

To reproduce the error condition with psycopg2 2.4, change to:

        def escape(string):
            return str(psycopg2.extensions.QuotedString(string, "Tally", "ho!"))

Revision history for this message
John-Magne Bredal (john-m-bredal) wrote :

NAV 3.14 is not longer supported

Changed in nav:
status: New → Invalid
Revision history for this message
Morten Brekkevold (mbrekkevold) wrote :

We haven't confirmed that this is not still a problem in 4.2, so re-opening

Changed in nav:
status: Invalid → New
Revision history for this message
Ole Martin Bjørndalen (olemb) wrote :

I made a mistake when I investigated this. It turns out QuotedString() defaults to latin-1:

    >>> from psycopg2.extensions import QuotedString
    >>> psycopg2.extensions.QuotedString(u'\xf8').encoding
   'latin-1'

In 2.4 you can override this with a second argument but this was removed in 2.5. Since NAV requires 2.4.3 this is not a problem for now.

Revision history for this message
Morten Brekkevold (mbrekkevold) wrote :

Although the enc parameter is gone from QuotedString, it only makes sense for unicode objects that need to be encoded first. My take is to explicitly encode unicode objects before passing them to QuotedString.

Fix committed here: https://nav.uninett.no/hg/stable/rev/ee55821142b5

Changed in nav:
status: New → In Progress
importance: Undecided → Medium
assignee: nobody → Morten Brekkevold (mbrekkevold)
milestone: none → 4.3.0
summary: - Report pages crash with NAV 3.14 and psycopg2 2.5.1
+ Report pages crash under psycopg2 >= 2.5
Changed in nav:
status: In Progress → Fix Committed
Changed in nav:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.