Skip to content

Commit 242dfaa

Browse files
Try another test fix
1 parent 50c84d2 commit 242dfaa

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

docs/mysql57_support.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ MySQL 5.7, MySQL 8.0+ and `use_column_name_cache`
55

66
In MySQL 5.7 and earlier, the binary log events for row-based replication do not include column name metadata. This means that `python-mysql-replication` cannot map column values to their names directly from the binlog event.
77

8-
Starting with MySQL 8.0.1, the `binlog_row_metadata` system variable was introduced to control the amount of metadata written to the binary log. The default value for this variable is `MINIMAL`, which provides the same behavior as MySQL 5.7.
8+
Starting with MySQL 8.0.1, the `binlog_row_metadata` system variable was introduced to control the amount of metadata written to the binary log. This is a **GLOBAL** and **DYNAMIC** variable. The default value for this variable is `MINIMAL`, which provides the same behavior as MySQL 5.7.
99

1010
The Problem
1111
-----------
1212

13-
When column metadata is not present in the binlog (as in MySQL 5.7 and earlier, or when `binlog_row_metadata` is set to `MINIMAL` in MySQL 8.0+), the `values` dictionary in a `WriteRowsEvent`, `UpdateRowsEvent`, or `DeleteRowsEvent` will contain integer keys corresponding to the column index, not the column names.
13+
When column metadata is not present in the binlog (as in MySQL 5.7 and earlier, or when `binlog_row_metadata` is set to `MINIMAL` globally in MySQL 8.0+), the `values` dictionary in a `WriteRowsEvent`, `UpdateRowsEvent`, or `DeleteRowsEvent` will contain integer keys corresponding to the column index, not the column names.
1414

1515
For example, for a table `users` with columns `id` and `name`, an insert event might look like this:
1616

@@ -32,7 +32,7 @@ This allows you to receive row data with column names as keys.
3232
MySQL 8.0+ with `binlog_row_metadata=FULL`
3333
------------------------------------------
3434

35-
In MySQL 8.0.1 and later, you can set `binlog_row_metadata` to `FULL`. When this setting is enabled, the column names are included directly in the binlog events, and `use_column_name_cache` is not necessary.
35+
In MySQL 8.0.1 and later, you can set `binlog_row_metadata` to `FULL` using `SET GLOBAL binlog_row_metadata = 'FULL'`. When this setting is enabled, the column names are included directly in the binlog events, and `use_column_name_cache` is not necessary.
3636

3737
Example
3838
-------

pymysqlreplication/tests/test_basic.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,24 @@ def test_write_row_event(self):
272272
self.assertEqual(event.columns[1].name, "data")
273273

274274
def test_fetch_column_names_from_schema(self):
275-
# This test is for MySQL 5.7+
276-
if not self.isMySQL57AndMore():
277-
self.skipTest("Test for MySQL 5.7+ where binlog_row_metadata can be MINIMAL")
275+
# This test is for scenarios where column names are NOT in the binlog
276+
# (MySQL 5.7 or older, or MySQL 8.0+ with binlog_row_metadata=MINIMAL)
278277

279-
# Minimal is only supported for MySQL 8 and later
280-
if self.isMySQL80AndMore():
281-
self.execute("SET SESSION binlog_row_metadata = 'MINIMAL'")
278+
# Check if binlog_row_metadata exists (MySQL 8.0+)
279+
try:
280+
cursor = self.execute("SHOW GLOBAL VARIABLES LIKE 'binlog_row_metadata'")
281+
result = cursor.fetchone()
282+
if result:
283+
global_binlog_row_metadata = result[1]
284+
if global_binlog_row_metadata == 'FULL':
285+
self.skipTest("binlog_row_metadata is FULL globally, use_column_name_cache is not needed")
286+
# If result is None, binlog_row_metadata doesn't exist (MySQL 5.7 or older), so proceed
287+
except pymysql.err.OperationalError as e:
288+
if e.args[0] == 1193: # ER_UNKNOWN_SYSTEM_VARIABLE
289+
# Variable doesn't exist, likely MySQL 5.7 or older, so proceed
290+
pass
291+
else:
292+
raise
282293

283294
query = "CREATE TABLE test_column_cache (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))"
284295
self.execute(query)
@@ -318,8 +329,6 @@ def test_fetch_column_names_from_schema(self):
318329

319330
# Reset and replay events
320331
self.resetBinLog()
321-
if self.isMySQL80AndMore():
322-
self.execute("SET SESSION binlog_row_metadata = 'MINIMAL'")
323332
self.execute("INSERT INTO test_column_cache (data) VALUES('World')")
324333
self.execute("COMMIT")
325334

@@ -340,8 +349,6 @@ def test_fetch_column_names_from_schema(self):
340349
self.assertNotIn("data", event.rows[0]["values"])
341350

342351
# cleanup
343-
if self.isMySQL80AndMore():
344-
self.execute("SET SESSION binlog_row_metadata = 'FULL'")
345352
row_event._COLUMN_NAME_CACHE.clear()
346353

347354

0 commit comments

Comments
 (0)