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

When error occurs, Print very long sql may obstruct debugging #13

Closed
void285 opened this issue Nov 11, 2022 · 3 comments
Closed

When error occurs, Print very long sql may obstruct debugging #13

void285 opened this issue Nov 11, 2022 · 3 comments

Comments

@void285
Copy link
Collaborator

void285 commented Nov 11, 2022

I just encountered with a mysql related error, and find error printing in base.py may obstruct debugging when the sql is very long, so I change it like this:

            if len(self.sql) <= 300:
                raise type(ex)(str(ex) + ":\n" + self.sql)
            else:
                raise type(ex)(str(ex) + ":\n" + self.sql[:300] + "\tsql length: " + str(len(self.sql)))

I tried to insert 100 records in one batch, the sql it very long, in this case about 5M, to solve the problem, I have to reduce the amount the records in a batch, this is a mysql related issue, maybe not due to pymedoo.

The error I got is as below, print the whole sql is terrible, so I modify base.py to print the slim version:

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/mysql/connector/network.py", line 159, in send_plain
    self.sock.sendall(packet)
BrokenPipeError: [Errno 32] Broken pipe

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

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/medoo/base.py", line 139, in query
    self.cursor.execute(self.sql)
  File "/usr/lib/python3.9/site-packages/mysql/connector/cursor.py", line 564, in execute
    self._handle_result(self._connection.cmd_query(stmt))
  File "/usr/lib/python3.9/site-packages/mysql/connector/connection.py", line 990, in cmd_query
    result = self._handle_result(self._send_cmd(ServerCmd.QUERY, query))
  File "/usr/lib/python3.9/site-packages/mysql/connector/connection.py", line 620, in _send_cmd
    self._socket.send(
  File "/usr/lib/python3.9/site-packages/mysql/connector/network.py", line 161, in send_plain
    raise OperationalError(
mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'localhost:3306', system error: 32 Broken pipe

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/e/todb.py", line 531, in <module>
    populate_items(seq)
  File "/e/todb.py", line 449, in populate_items
    dbs.insert('table_%s' % (seq), *batch)
  File "/usr/lib/python3.9/site-packages/medoo/base.py", line 83, in insert
    return self.query(sql, kwargs.get("commit", True))
  File "/usr/lib/python3.9/site-packages/medoo/base.py", line 150, in query
    raise type(ex)(str(ex) + ":\n" + self.sql[:300] + "\tsql length: " + str(len(self.sql)))
mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'localhost:3306', system error: 32 Broken pipe:
INSERT INTO `items` VALUES ('12650774',2973,1637632343,'\r\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum." sql length: 5062186
2055
Exception ignored in: <function Base.__del__ at 0x6fffff894ee0>
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/medoo/base.py", line 56, in __del__
  File "/usr/lib/python3.9/site-packages/medoo/base.py", line 46, in close
  File "/usr/lib/python3.9/site-packages/mysql/connector/connection.py", line 585, in close
  File "/usr/lib/python3.9/site-packages/mysql/connector/connection.py", line 1074, in cmd_quit
  File "/usr/lib/python3.9/site-packages/mysql/connector/network.py", line 161, in send_plain
  File "/usr/lib/python3.9/site-packages/mysql/connector/errors.py", line 186, in __init__
  File "/usr/lib/python3.9/site-packages/mysql/connector/locales/__init__.py", line 61, in get_client_error
ImportError: No localization support for language 'eng'

@void285
Copy link
Collaborator Author

void285 commented Nov 11, 2022

About the mysql related error, FYI https://stackoverflow.com/questions/1884859/lost-connection-to-mysql-server-during-query

The mysql docs have a whole page dedicated to this error: http://dev.mysql.com/doc/refman/5.0/en/gone-away.html

of note are

You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's max_allowed_packet variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given in Section B.5.2.10, “Packet too large”.

You can get more information about the lost connections by starting mysqld with the --log-warnings=2 option. This logs some of the disconnected errors in the hostname.err file

@pwwang
Copy link
Owner

pwwang commented Nov 11, 2022

Sounds good to me. Mind submitting a PR?

@pwwang
Copy link
Owner

pwwang commented Nov 11, 2022

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