Unicode errors with PostgreSQL and RawStr fields

Bug #1236297 reported by Aurélien Bompard
12
This bug affects 2 people
Affects Status Importance Assigned to Milestone
GNU Mailman
Invalid
High
Barry Warsaw

Bug Description

When using PostgreSQL as a database, it's impossible to set the moderator_password field of a mailing list, which is of type RawStr.
To be precise, it's possible to set it, but getting it back from the database after a commit will cause a TypeError with the message:
"Expected str, found <type 'unicode'>" as if PostgreSQL always returned unicode on TEXT fields and Storm did not convert them to bytestrings. I get no errors on an SQLite database.

I don't know if the problem comes from Mailman or Storm. I have written a python script to reproduce it, see the attached file. There are comments, it should be easily readable.

Tags: mailman3

Related branches

Revision history for this message
Aurélien Bompard (abompard) wrote :
Revision history for this message
Aurélien Bompard (abompard) wrote :

I found why! In "mailman/src/mailman/database/schema/postgres.sql", the moderator_password field is of type "TEXT" instead of being "BYTEA". As a result, the psycopg2 driver converts it to an unicode string.
This is coherent with the Storm manual which states that RawStr types should be set as BYTEA types in PostgreSQL:
https://storm.canonical.com/Manual#Table_of_properties_vs._python_vs._database_types

I believe a schema migration script will be needed.

Revision history for this message
Aurélien Bompard (abompard) wrote :

Here's the schema migration script, it's pretty simple.
I'm converting existing data to ASCII and not UTF-8 because we don't expect non-ascii chars to be in the moderator_password column (it should contain the result of the config.password_context.encrypt() function, which is ASCII-only.

Barry Warsaw (barry)
Changed in mailman:
milestone: none → 3.0.0b4
assignee: nobody → Barry Warsaw (barry)
importance: Undecided → High
status: New → In Progress
Barry Warsaw (barry)
Changed in mailman:
milestone: 3.0.0b4 → 3.0.0b5
Revision history for this message
Aurélien Bompard (abompard) wrote :

This bug is no longer valid since Storm has been replaced by SQLAlchemy.

Changed in mailman:
status: In Progress → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

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