Skip to content

Conversation

Copy link

Copilot AI commented Dec 16, 2025

Tests were expecting MySQL error 1093 for DELETE statements with self-referencing subqueries, but EF Core's query generation using derived tables within EXISTS clauses bypasses this limitation on both MySQL and MariaDB.

Query pattern that works:

DELETE `o` FROM `Order Details` AS `o`
WHERE EXISTS (
    SELECT 1 FROM (
        SELECT `o0`.`OrderID`, `o0`.`ProductID`
        FROM `Order Details` AS `o0`
        WHERE `o0`.`OrderID` < 10300
        LIMIT @p
    ) AS `o1`  -- Derived table materializes result, avoiding error 1093
    WHERE (`o1`.`OrderID` = `o`.`OrderID`) AND (`o1`.`ProductID` = `o`.`ProductID`))

Changes:

  • Removed conditional Assert.ThrowsAsync<MySqlException> blocks from 7 test methods
  • Tests now execute normally on both MySQL 8.0.40+ and MariaDB 11.6.2+
  • Affected tests:
    • Delete_Where_Take
    • Delete_Where_Skip
    • Delete_Where_Skip_Take
    • Delete_Where_OrderBy_Skip
    • Delete_Where_OrderBy_Take
    • Delete_Where_OrderBy_Skip_Take
    • Delete_Where_Skip_Take_Skip_Take_causing_subquery

Note: Direct self-references without derived tables still correctly fail with error 1093 (e.g., Delete_Where_OrderBy test correctly expects exception for queries lacking the derived table wrapper).

Original prompt

This section details on the original issue you should resolve

<issue_title>Assert.Throws() Failure: No exception was thrown</issue_title>
<issue_description> Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.BulkUpdates.NorthwindBulkUpdatesMySqlTest.Delete_Where_Take(async: False) [58 ms]
Error Message:
Assert.Throws() Failure: No exception was thrown
Expected: typeof(MySqlConnector.MySqlException)
Stack Trace:
at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.BulkUpdates.NorthwindBulkUpdatesMySqlTest.Delete_Where_Take(Boolean async) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesMySqlTest.cs:line 320
--- End of stack trace from previous location ---

Failed Pomelo.EntityFrameworkCore.MySql.FunctionalTests.BulkUpdates.NorthwindBulkUpdatesMySqlTest.Delete_Where_Take(async: True) [26 ms]
Error Message:
Assert.Throws() Failure: No exception was thrown
Expected: typeof(MySqlConnector.MySqlException)
Stack Trace:
at Pomelo.EntityFrameworkCore.MySql.FunctionalTests.BulkUpdates.NorthwindBulkUpdatesMySqlTest.Delete_Where_Take(Boolean async) in /home/runner/work/Pomelo.EntityFrameworkCore.MySql/Pomelo.EntityFrameworkCore.MySql/test/EFCore.MySql.FunctionalTests/BulkUpdates/NorthwindBulkUpdatesMySqlTest.cs:line 320
--- End of stack trace from previous location ---</issue_description>

<agent_instructions>restore, build, ensure mysql 8.0.40 is running, run test, fix code, retest before committing also against mariadb 11.6.2.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

The tests incorrectly expected MySQL to throw error 1093 for DELETE queries with derived tables.
The SQL pattern generated by EF Core uses derived tables (AS `o1`) within EXISTS clauses, which
materializes the intermediate result and avoids MySQL's error 1093 "You can't specify target table
for update in FROM clause". This pattern works on both MySQL and MariaDB.

Fixed tests:
- Delete_Where_Take
- Delete_Where_Skip
- Delete_Where_Skip_Take
- Delete_Where_OrderBy_Skip
- Delete_Where_OrderBy_Take
- Delete_Where_OrderBy_Skip_Take
- Delete_Where_Skip_Take_Skip_Take_causing_subquery

Tests now pass on both MySQL 8.0.40 and MariaDB 11.6.2.

Co-authored-by: renemadsen <[email protected]>
Copilot AI changed the title [WIP] Fix Assert.Throws failure in BulkUpdates test Remove incorrect exception expectations from DELETE tests with derived tables Dec 16, 2025
Copilot AI requested a review from renemadsen December 16, 2025 15:22
@renemadsen renemadsen marked this pull request as ready for review December 16, 2025 17:52
@renemadsen renemadsen merged commit 933b4e4 into master Dec 16, 2025
24 of 55 checks passed
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

Successfully merging this pull request may close these issues.

Assert.Throws() Failure: No exception was thrown

2 participants