dolthub / doltpy

A Python API for Dolt
Apache License 2.0
56 stars 13 forks source link

Database error #139

Open evanirla opened 3 years ago

evanirla commented 3 years ago

I am receiving a database error when calling the sync_to_dolt function from doltpy.sql.sync, where it almost looks like the database name is null, but I don't seem to have the option of setting it in the ServerConfiguration instance or Dolt instance.


  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 1705, in _execute_context
    self.dialect.do_execute(
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\default.py", line 681, in do_execute
    cursor.execute(statement, parameters)
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 569, in execute     
    self._handle_result(self._connection.cmd_query(stmt))
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection.py", line 599, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection.py", line 487, in _handle_result
    raise errors.get_exception(packet)
mysql.connector.errors.DatabaseError: 1105 (HY000): syntax error at position 25 near 'FROM'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:\Users\evani\git\metamonster\metamonster\main.py", line 16, in <module>
    main()
  File "C:\Users\evani\git\metamonster\metamonster\main.py", line 12, in main
    args.func(args)
  File "C:\Users\evani\git\metamonster\metamonster\sync.py", line 137, in sync
    database.sync(config.dolt_config)
  File "C:\Users\evani\git\metamonster\metamonster\sync.py", line 58, in sync
    sync_to_dolt(reader, writer, self.mappings)
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\doltpy\sql\sync\sync_tools.py", line 37, in sync_to_dolt
    _sync_helper(source_reader, target_writer, table_map)
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\doltpy\sql\sync\sync_tools.py", line 66, in _sync_helper
    target_writer(remapped)
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\doltpy\sql\sync\dolt.py", line 35, in inner
    metadata.reflect()
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\sql\schema.py", line 4670, in reflect     
    available = util.OrderedSet(insp.get_table_names(schema))
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\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 "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\reflection.py", line 55, in cache  
    ret = fn(self, con, *args, **kw)
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\dialects\mysql\base.py", line 2956, in get_table_names
    rp = connection.exec_driver_sql(
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 1575, in exec_driver_sql
    return self._exec_driver_sql(
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 1484, in _exec_driver_sql
    ret = self._execute_context(
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 1748, in _execute_context
    self._handle_dbapi_exception(
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 1929, in _handle_dbapi_exception
    util.raise_(
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\util\compat.py", line 198, in raise_      
    raise exception
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\base.py", line 1705, in _execute_context
    self.dialect.do_execute(
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\sqlalchemy\engine\default.py", line 681, in do_execute
    cursor.execute(statement, parameters)
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\cursor.py", line 569, in execute     
    self._handle_result(self._connection.cmd_query(stmt))
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection.py", line 599, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "C:\Users\evani\AppData\Local\Programs\Python\Python39\lib\site-packages\mysql\connector\connection.py", line 487, in _handle_result
    raise errors.get_exception(packet)
sqlalchemy.exc.DatabaseError: (mysql.connector.errors.DatabaseError) 1105 (HY000): syntax error at position 25 near 'FROM'
[SQL: SHOW FULL TABLES FROM ``]
(Background on this error at: http://sqlalche.me/e/14/4xp6)```
evanirla commented 3 years ago

Looks like it is coming from the sqlalchemy engine in the DoltSQLServerContext not having the database appended to the url.

Engine(mysql+mysqlconnector://root@127.0.0.1:3307/)

This seems to come from the fact that I am setting the repo_dir to ./ and the repo_name property in the Dolt class does a string split to parse out the repo name. If I am right, could I request that Dolt allows a repo name to be set in the metadata? That or doltpy needs to do a SHOW DATABASES call against the MySQL database.