ibmdb/python-ibmdbsa

pyodbc400: NameError: name 'unicode' is not defined. Did you mean: 'Unicode'?

rfx77 opened this issue · 2 comments

rfx77 commented

the function unicode is not available in python 3.10. you have to use Unicode instead or redefine it in reflection.py


Traceback (most recent call last):
  File "C:\develop\test\python05\sqla.py", line 18, in <module>
    tbgp = Table("tbgp", metadata_obj, autoload_with=e, schema="testlib3")
  File "<string>", line 2, in __new__
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\util\deprecations.py", line 281, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\sql\schema.py", line 437, in __new__
    return cls._new(*args, **kw)
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\sql\schema.py", line 491, in _new
    with util.safe_reraise():
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\util\langhelpers.py", line 147, in __exit__
    raise exc_value.with_traceback(exc_tb)
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\sql\schema.py", line 487, in _new
    table.__init__(name, metadata, *args, _no_init=False, **kw)
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\sql\schema.py", line 867, in __init__
    self._autoload(
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\sql\schema.py", line 899, in _autoload
    conn_insp.reflect_table(
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\engine\reflection.py", line 1526, in reflect_table
    _reflect_info = self._get_reflection_info(
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\engine\reflection.py", line 2008, in _get_reflection_info
    columns=run(
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\engine\reflection.py", line 1994, in run
    res = meth(filter_names=_fn, **kw)
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\engine\reflection.py", line 921, in get_multi_columns
    table_col_defs = dict(
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\engine\default.py", line 1098, in _default_multi_reflect
    single_tbl_method(
  File "C:\develop\test\python05\venv\lib\site-packages\ibm_db_sa\base.py", line 734, in get_columns
    return self._reflector.get_columns(connection, table_name, schema=schema, **kw)
  File "<string>", line 2, in get_columns
  File "C:\develop\test\python05\venv\lib\site-packages\sqlalchemy\engine\reflection.py", line 97, in cache
    ret = fn(self, con, *args, **kw)
  File "C:\develop\test\python05\venv\lib\site-packages\ibm_db_sa\reflection.py", line 684, in get_columns
    'nullable': r[3] == unicode('Y'),
NameError: name 'unicode' is not defined. Did you mean: 'Unicode'?

Hello @rfx77
Can you please share sample repo to reproduce this issue?
As I have given a input of Unicode text that is "Hello, 你好, नमस्ते, مرحبا", and I'm able to retrieve the output,
below is the example as I have given input :-

insert_query = text("INSERT INTO unicode_example (unicode_text) VALUES ('Hello, 你好, नमस्ते, مرحبا')")
connection.execute(insert_query)
rfx77 commented

You have to use pyodbc400.

This is an example code
tbgp = Table("tbgp", metadata_obj, autoload_with=e, schema="testlib3")

in the trace above you can see the codelines wher the unicode function is called.

here you have a code which calls non existing unicode function:

where(systbl.c.tabtype == unicode('T')).\