sqlalchemy-firebird icon indicating copy to clipboard operation
sqlalchemy-firebird copied to clipboard

exception reading text blobs from Firebird

Open hmoffatt opened this issue 6 months ago • 2 comments

Describe the bug I have database columns of type BLOB SUB_TYPE 1. My code is working fine SQLAlchemy 1.4.54 and sqlalchemy-firebird 0.8.0, but when I run with 2.0.39 and 2.1, I am getting errors

TypeError: string argument without an encoding

This is occurring with both firebird+fdb and firebird+firebird. charset is set to UTF8 or utf-8 in the connection string.

To Reproduce

  1. Create database and populate:
CREATE TABLE THE_BLOB (TEXT BLOB SUB_TYPE TEXT SEGMENT SIZE 80);
insert into the_blob values ('hi');
  1. Fetch rows:
import os

from sqlalchemy import MetaData, create_engine
from sqlalchemy.sql import select

db = create_engine(
    "firebird+firebird://%s:%s@%s:%d/%s?charset=utf-8"
    % ("SYSDBA", "masterkey", "localhost", 3050, os.path.join(os.getcwd(), "blob.fdb")),
)


metadata = MetaData()
metadata.bind = db
metadata.reflect(db)

blob_table = metadata.tables["the_blob"]

with db.connect() as conn:
    blobs = conn.execute(select(blob_table))
    for row in blobs:
        print(row)

  1. See error:
Traceback (most recent call last):
  File "/home/hamish/dev/pyservices/blobtest.py", line 37, in <module>
    for row in blobs:
  File "/home/hamish/dev/pyservices/venv/lib/python3.11/site-packages/sqlalchemy/engine/result.py", line 529, in iterrows
    make_row(raw_row) if make_row else raw_row
    ^^^^^^^^^^^^^^^^^
  File "lib/sqlalchemy/cyextension/resultproxy.pyx", line 22, in sqlalchemy.cyextension.resultproxy.BaseRow.__init__
  File "lib/sqlalchemy/cyextension/resultproxy.pyx", line 79, in sqlalchemy.cyextension.resultproxy._apply_processors
  File "/home/hamish/dev/pyservices/venv/lib/python3.11/site-packages/sqlalchemy/sql/sqltypes.py", line 921, in process
    value = bytes(value)
            ^^^^^^^^^^^^
TypeError: string argument without an encoding

Expected behavior Blob should be returned. When run on sqlalchemy 1, this runs successfully:

$ python3 blobtest.py
('hi',)

Desktop (please complete the following information):

  • OS: Debian Linux 12
  • sqlalchemy 2.0.39
  • sqlalchemy-firebird 2.1

hmoffatt avatar Jun 19 '25 06:06 hmoffatt

Working on it.

fdcastel avatar Jul 04 '25 03:07 fdcastel

Fixed on #82.

fdcastel avatar Jul 04 '25 05:07 fdcastel