fix: select contexts by contextIds regardless of fullyQualifiedTableNames - #1551
Merged
jeffgbutler merged 2 commits intoJul 25, 2026
Merged
Conversation
…ames calculateContextsToRun() branched on fullyQualifiedTableNames.isEmpty() to decide whether to run all contexts or only the ones named in contextIds. As a result, supplying contextIds without any fullyQualifiedTableNames ran every context instead of the requested subset, a regression from 1.4.2 and earlier. Context selection and table-name filtering are independent concerns: the table names are applied later during introspection. Branch on contextIds.isEmpty() so the requested contexts are honored whether or not table names are also supplied. contextIds is a final, non-null HashSet, so no null guard is needed. Adds a database-free test that invokes calculateContextsToRun() via reflection and covers contextIds-only, no-contextIds, and contextIds-with-table-name. Closes mybatis#1547
jeffgbutler
reviewed
Jul 20, 2026
jeffgbutler
left a comment
Member
There was a problem hiding this comment.
Please don't use reflection for testing. Make the method under test have package private visibility, then tests in the same package can see it.
Make the method under test package private and move the test into the same package so it can call it directly, as requested in review.
Contributor
Author
|
Done in f1671a4. The method is package private now and the test moved into org.mybatis.generator.api so it calls it directly, no reflection. Core suite still passes (1289 tests). |
Member
|
Thanks! |
Contributor
Author
|
Thanks for getting this in. Appreciate you taking the contextIds selection fix so callers do not have to pass table names too. |
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.
Summary
Fixes #1547: when a caller supplies
contextIdsbut nofullyQualifiedTableNames, MyBatis Generator ignores thecontextIdsand runs every context instead of the requested subset. This restores the pre-2.0 selection behavior. The regression was confirmed by @jeffgbutler in the issue thread.Background
MyBatisGenerator.calculateContextsToRun()decides whether to run all configured contexts or only the subset named incontextIds. In 2.0 it branches on whetherfullyQualifiedTableNamesis empty:Context selection and table-name filtering are independent concerns — the table names are applied later, during introspection in
runContextIntrospection. Tying context selection to the table-name set means that callinggenerate(callback, contextIds, Collections.emptySet())runs every context, ignoringcontextIds. In 1.4.2 and earlier the subset selection worked as expected.Fix
Branch on
contextIds.isEmpty()instead:contextIdsis a final, non-nullHashSet, so no null guard is needed. The "run all contexts" branch is now taken only when nocontextIdsare specified, regardless of whether table names are also supplied.Testing
Added a database-free unit test that invokes the private
calculateContextsToRun()via reflection (validation runs insidegenerate(), so aMyBatisGeneratorbuilt with minimal contexts needs no live database) and covers three cases:contextIdssupplied, no table names → only the requested context runs (the reported regression);contextIds→ all contexts run;contextIdssupplied together with a table name → still only the requested context.MyBatisGeneratorTestpasses with the fix; the new test fails against the unpatched code (it runs both contexts), confirming it catches the regression.Closes #1547
AI was used for assistance.