Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql and Python 3.8 #390

Open
ddofborg opened this issue Dec 22, 2021 · 7 comments
Open

Mysql and Python 3.8 #390

ddofborg opened this issue Dec 22, 2021 · 7 comments

Comments

@ddofborg
Copy link

ddofborg commented Dec 22, 2021

I am trying to use dataset with MySQL 8.

I noticed MySQLDB is not really supported on Python3 and I found mysqlclient, which replaces MySQLDB for Python 3.

When I run the following:

import dataset
db = dataset.connect('mysql://un:pw@localhost')
db.tables()

I get:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/dataset/venv/lib/python3.8/site-packages/dataset/database.py", line 184, in tables
    return self.inspect.get_table_names(schema=self.schema)
  File "/home/dataset/venv/lib/python3.8/site-packages/sqlalchemy/engine/reflection.py", line 266, in get_table_names
    return self.dialect.get_table_names(
  File "<string>", line 2, in get_table_names
  File "/home/dataset/venv/lib/python3.8/site-packages/sqlalchemy/engine/reflection.py", line 55, in cache
    ret = fn(self, con, *args, **kw)
  File "/home/dataset/venv/lib/python3.8/site-packages/sqlalchemy/dialects/mysql/base.py", line 2786, in get_table_names
    % self.identifier_preparer.quote_identifier(current_schema)
  File "/home/dataset/venv/lib/python3.8/site-packages/sqlalchemy/sql/compiler.py", line 5120, in quote_identifier
    + self._escape_identifier(value)
  File "/home/dataset/venv/lib/python3.8/site-packages/sqlalchemy/sql/compiler.py", line 5079, in _escape_identifier
    value = value.replace(self.escape_quote, self.escape_to_quote)
AttributeError: 'NoneType' object has no attribute 'replace'

I get this error for basically all commands. Any ideas what this could be?

@pudo
Copy link
Owner

pudo commented Dec 23, 2021

Hmmm I'm not sure what's happening there. Can you share the list of table names in the given database? One of them might contain only special characters and get normalized to None...

@pudo pudo closed this as completed Dec 23, 2021
@pudo pudo reopened this Dec 23, 2021
@pudo
Copy link
Owner

pudo commented Dec 23, 2021

Wrong button, good morning :)

@ddofborg
Copy link
Author

It's a clean install of MySQL v8 on Ubuntu, only default databases and tables. I do see a utf8mb4 encoding of the tables. Could that be it?

Screenshot 2021-12-23 at 10 51 05

PS. Maybe it's good to update the docs and remove MySQLDB from there.

@ddofborg
Copy link
Author

If it helps, I can add the print somewhere to see the value before normalisation. Just let me know where normalisation happens, and I will print before that.

@pudo
Copy link
Owner

pudo commented Dec 23, 2021

The only thing we're passing in there is schema, which is None as a default. This should be possible:

https://docs.sqlalchemy.org/en/14/core/reflection.html#sqlalchemy.engine.reflection.Inspector.get_table_names

Can you try and remove the self.schema from /home/dataset/venv/lib/python3.8/site-packages/dataset/database.py:184?

@ddofborg
Copy link
Author

You mean from:

    @property
    def tables(self):
        """Get a listing of all tables that exist in the database."""
        return self.inspect.get_table_names(schema=self.schema)

to:

    @property
    def tables(self):
        """Get a listing of all tables that exist in the database."""
        return self.inspect.get_table_names()

Same thing...

@pudo
Copy link
Owner

pudo commented Dec 27, 2021

Hmmm I really don't understand how this is caused by dataset. Have you checked the upstream bug tracker at sqlalchemy to see if the issue is documented there? I don't have MySQL set up to test so it's a bit hard to debug/replicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants