Skip to content

Commit b5c878a

Browse files
committed
BUG23582924: Fix array append operation of mysqlx.ModifyStatement
Using array_append with ModifyStatement results in AttributeError: AttributeError: 'EnumTypeWrapper' object has no attribute 'ARRAY_APPEND' `ARRAY_APPEND` is an enum value of `MySQLxCrud.UpdateOperation`. Removing `UpdateType` from `MySQLxCrud.UpdateOperation.UpdateType` resolves the issue. Tests were added for regression.
1 parent f4cc8d5 commit b5c878a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

lib/mysqlx/statement.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ def array_append(self, doc_path, value):
349349
mysqlx.ModifyStatement: ModifyStatement object.
350350
"""
351351
self._update_ops.append(
352-
UpdateSpec(MySQLxCrud.UpdateOperation.UpdateType.ARRAY_APPEND,
353-
doc_path, value))
352+
UpdateSpec(MySQLxCrud.UpdateOperation.ARRAY_APPEND, doc_path,
353+
value))
354354
return self
355355

356356
def execute(self):

tests/test_mysqlx_crud.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,18 @@ def test_parameter_binding(self):
333333
self.assertEqual(1, len(docs))
334334
self.assertEqual("Wilma", docs[0]["name"])
335335

336+
def test_array_append(self):
337+
collection_name = "collection_test"
338+
collection = self.schema.create_collection(collection_name)
339+
collection.add(
340+
{"_id": 1, "name": "Fred", "cards": []},
341+
{"_id": 2, "name": "Barney", "cards": [1, 2, 4]},
342+
{"_id": 3, "name": "Wilma", "cards": []},
343+
{"_id": 4, "name": "Betty", "cards": []},
344+
).execute()
345+
collection.modify("$._id == 2").array_append("$.cards[1]", 3).execute()
346+
docs = collection.find("$._id == 2").execute().fetch_all()
347+
self.assertEqual([1, [2, 3], 4], docs[0]["cards"])
336348

337349
@unittest.skipIf(tests.MYSQL_VERSION < (5, 7, 12), "XPlugin not compatible")
338350
class MySQLxTableTests(tests.MySQLxTests):

0 commit comments

Comments
 (0)