Refactor LOAD LOCAL INFILE handling - #1264
Merged
Merged
Conversation
Read the OK packet just after sending the EOF (enpty) packet.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1264 +/- ##
==========================================
- Coverage 86.24% 84.51% -1.74%
==========================================
Files 17 17
Lines 2436 2460 +24
Branches 258 247 -11
==========================================
- Hits 2101 2079 -22
- Misses 249 304 +55
+ Partials 86 77 -9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Refactors the client-side LOAD DATA LOCAL INFILE handling in pymysql/connections.py to align packet sequencing (send the empty/EOF packet, then immediately read the server’s response) and to simplify the local-file sending implementation.
Changes:
- Refactored
LOAD LOCAL INFILEflow to read the OK packet immediately after sending the terminating empty packet. - Replaced the
LoadLocalFilehelper class with a module-level_send_local_file()function. - Minor cleanup in OK packet handling and connection exception classification.
Suppressed comments (1)
pymysql/connections.py:1446
_send_local_file()no longer checks that the connection has an active socket; ifconn._sockisNone(e.g., connection closed mid-transfer),conn.write_packet()will raise an AttributeError. Add an explicit InterfaceError guard like other write paths use.
def _send_local_file(filename: str, conn: Connection):
"""Send data packets from the local file to the server"""
packet_size = min(conn.max_allowed_packet, 16 * 1024)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1296
to
+1303
| finally: | ||
| # send the empty packet to signify we are done sending data | ||
| conn.write_packet(b"") | ||
| ok_packet = conn._read_packet() | ||
| # If an error occurs while sending the file, exit here without handling | ||
| # the OK packet. | ||
|
|
||
| ok_packet = self.connection._read_packet() | ||
| if ( | ||
| not ok_packet.is_ok_packet() | ||
| ): # pragma: no cover - upstream induced protocol error | ||
| if not ok_packet.is_ok_packet(): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Read the OK packet just after sending the EOF (enpty) packet.
There is no problem with bare except clauses, but many people keep sending PRs to remove them, so we rewrite them using finally.