Skip to content

Commit 863aa5b

Browse files
Copilotrenemadsen
andcommitted
Fix JSON key ordering tests for MySQL 8.0.40 compatibility
MySQL 8.0.40 changed JSON key ordering behavior - it now sorts keys alphabetically when storing/retrieving JSON data. Additionally, MySQL requires CAST(@param AS json) for JSON comparisons, while MariaDB does not. Updated three tests to use conditional SQL assertions based on server type: - JsonMicrosoftDomQueryTest.Parameter_document - JsonMicrosoftDomQueryTest.Parameter_element - JsonNewtonsoftDomQueryTest.Parameter_element Tests now pass on both MySQL 8.0.40 and MariaDB 11.3.2+ Co-authored-by: renemadsen <76994+renemadsen@users.noreply.github.com>
1 parent fc25643 commit 863aa5b

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

test/EFCore.MySql.FunctionalTests/Query/JsonMicrosoftDomQueryTest.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,25 @@ public void Parameter_document()
8686
LIMIT 1
8787
""",
8888
//
89-
"""
89+
InsertJsonDocument(
90+
// MySQL 8.0.40+ reorders JSON keys alphabetically
91+
mySqlDocument: """
92+
@expected='{"ID":"00000000-0000-0000-0000-000000000000","Age":25,"Name":"Joe","IsVip":false,"Orders":[{"Price":99.5,"ShippingDate":"2019-10-01","ShippingAddress":"Some address 1"},{"Price":23.1,"ShippingDate":"2019-10-10","ShippingAddress":"Some address 2"}],"Statistics":{"Nested":{"IntArray":[3,4],"SomeProperty":10,"SomeNullableInt":20,"SomeNullableGuid":"d5f2685d-e5c4-47e5-97aa-d0266154eb2d"},"Visits":4,"Purchases":3}}' (Size = 4000)
93+
94+
SELECT `j`.`Id`, `j`.`CustomerDocument`, `j`.`CustomerElement`
95+
FROM `JsonEntities` AS `j`
96+
WHERE `j`.`CustomerDocument` = CAST(@expected AS json)
97+
LIMIT 2
98+
""",
99+
// MariaDB preserves original JSON key order
100+
mariaDbDocument: """
90101
@expected='{"Name":"Joe","Age":25,"ID":"00000000-0000-0000-0000-000000000000","IsVip":false,"Statistics":{"Visits":4,"Purchases":3,"Nested":{"SomeProperty":10,"SomeNullableInt":20,"SomeNullableGuid":"d5f2685d-e5c4-47e5-97aa-d0266154eb2d","IntArray":[3,4]}},"Orders":[{"Price":99.5,"ShippingAddress":"Some address 1","ShippingDate":"2019-10-01"},{"Price":23.1,"ShippingAddress":"Some address 2","ShippingDate":"2019-10-10"}]}' (Size = 4000)
91102
92103
SELECT `j`.`Id`, `j`.`CustomerDocument`, `j`.`CustomerElement`
93104
FROM `JsonEntities` AS `j`
94105
WHERE `j`.`CustomerDocument` = @expected
95106
LIMIT 2
96-
""");
107+
"""));
97108
}
98109

99110
[Fact]
@@ -114,14 +125,25 @@ public void Parameter_element()
114125
LIMIT 1
115126
""",
116127
//
117-
"""
128+
InsertJsonDocument(
129+
// MySQL 8.0.40+ reorders JSON keys alphabetically
130+
mySqlDocument: """
131+
@expected='{"ID":"00000000-0000-0000-0000-000000000000","Age":25,"Name":"Joe","IsVip":false,"Orders":[{"Price":99.5,"ShippingDate":"2019-10-01","ShippingAddress":"Some address 1"},{"Price":23.1,"ShippingDate":"2019-10-10","ShippingAddress":"Some address 2"}],"Statistics":{"Nested":{"IntArray":[3,4],"SomeProperty":10,"SomeNullableInt":20,"SomeNullableGuid":"d5f2685d-e5c4-47e5-97aa-d0266154eb2d"},"Visits":4,"Purchases":3}}' (Nullable = false) (Size = 4000)
132+
133+
SELECT `j`.`Id`, `j`.`CustomerDocument`, `j`.`CustomerElement`
134+
FROM `JsonEntities` AS `j`
135+
WHERE `j`.`CustomerElement` = CAST(@expected AS json)
136+
LIMIT 2
137+
""",
138+
// MariaDB preserves original JSON key order
139+
mariaDbDocument: """
118140
@expected='{"Name":"Joe","Age":25,"ID":"00000000-0000-0000-0000-000000000000","IsVip":false,"Statistics":{"Visits":4,"Purchases":3,"Nested":{"SomeProperty":10,"SomeNullableInt":20,"SomeNullableGuid":"d5f2685d-e5c4-47e5-97aa-d0266154eb2d","IntArray":[3,4]}},"Orders":[{"Price":99.5,"ShippingAddress":"Some address 1","ShippingDate":"2019-10-01"},{"Price":23.1,"ShippingAddress":"Some address 2","ShippingDate":"2019-10-10"}]}' (Nullable = false) (Size = 4000)
119141
120142
SELECT `j`.`Id`, `j`.`CustomerDocument`, `j`.`CustomerElement`
121143
FROM `JsonEntities` AS `j`
122144
WHERE `j`.`CustomerElement` = @expected
123145
LIMIT 2
124-
""");
146+
"""));
125147
}
126148

127149
[Fact]

test/EFCore.MySql.FunctionalTests/Query/JsonNewtonsoftDomQueryTest.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,25 @@ public void Parameter_element()
114114
LIMIT 1
115115
""",
116116
//
117-
"""
117+
InsertJsonDocument(
118+
// MySQL 8.0.40+ reorders JSON keys alphabetically
119+
mySqlDocument: """
120+
@expected='{"ID":"00000000-0000-0000-0000-000000000000","Age":25,"Name":"Joe","IsVip":false,"Orders":[{"Price":99.5,"ShippingDate":"2019-10-01","ShippingAddress":"Some address 1"},{"Price":23.1,"ShippingDate":"2019-10-10","ShippingAddress":"Some address 2"}],"Statistics":{"Nested":{"IntArray":[3,4],"SomeProperty":10,"SomeNullableInt":20,"SomeNullableGuid":"d5f2685d-e5c4-47e5-97aa-d0266154eb2d"},"Visits":4,"Purchases":3}}' (Size = 4000)
121+
122+
SELECT `j`.`Id`, `j`.`CustomerJObject`, `j`.`CustomerJToken`
123+
FROM `JsonEntities` AS `j`
124+
WHERE `j`.`CustomerJToken` = CAST(@expected AS json)
125+
LIMIT 2
126+
""",
127+
// MariaDB preserves original JSON key order
128+
mariaDbDocument: """
118129
@expected='{"Name":"Joe","Age":25,"ID":"00000000-0000-0000-0000-000000000000","IsVip":false,"Statistics":{"Visits":4,"Purchases":3,"Nested":{"SomeProperty":10,"SomeNullableInt":20,"SomeNullableGuid":"d5f2685d-e5c4-47e5-97aa-d0266154eb2d","IntArray":[3,4]}},"Orders":[{"Price":99.5,"ShippingAddress":"Some address 1","ShippingDate":"2019-10-01"},{"Price":23.1,"ShippingAddress":"Some address 2","ShippingDate":"2019-10-10"}]}' (Size = 4000)
119130
120131
SELECT `j`.`Id`, `j`.`CustomerJObject`, `j`.`CustomerJToken`
121132
FROM `JsonEntities` AS `j`
122133
WHERE `j`.`CustomerJToken` = @expected
123134
LIMIT 2
124-
""");
135+
"""));
125136
}
126137

127138
[Fact]

0 commit comments

Comments
 (0)