Skip to content

Fix createObjectContainer() uncaught PDOException on MySQL 8+#275

Merged
opengeek merged 1 commit intomodxcms:3.xfrom
opengeek:fix/207-mysql8-container
Apr 2, 2026
Merged

Fix createObjectContainer() uncaught PDOException on MySQL 8+#275
opengeek merged 1 commit intomodxcms:3.xfrom
opengeek:fix/207-mysql8-container

Conversation

@opengeek
Copy link
Copy Markdown
Member

@opengeek opengeek commented Mar 27, 2026

What changed and why

The createObjectContainer() method in all four driver managers probes for table existence with a bare SELECT COUNT(*) FROM {table}. On MySQL 8+ (and any driver configured with PDO::ERRMODE_EXCEPTION), this query throws a PDOException when the table does not yet exist. The exception was not caught, causing the method to abort instead of proceeding to CREATE TABLE. Closes #207.

Files and methods changed

  • src/xPDO/Om/mysql/xPDOManager.phpcreateObjectContainer(): wrap existence probe in try/catch
  • src/xPDO/Om/pgsql/xPDOManager.phpcreateObjectContainer(): same
  • src/xPDO/Om/sqlite/xPDOManager.phpcreateObjectContainer(): same
  • src/xPDO/Om/sqlsrv/xPDOManager.phpcreateObjectContainer(): same

Cross-driver impact

All four drivers (MySQL, PostgreSQL, SQLite, SQL Server) contained the identical bug. All four are fixed identically.

Test coverage

Added test/xPDO/Test/Om/xPDOManagerCreateObjectContainerTest.php with two test methods:

  • testCreateObjectContainerOnNonExistentTableReturnsTrue — primary regression test; forces ERRMODE_EXCEPTION and verifies no PDOException propagates when table is absent
  • testCreateObjectContainerOnExistingTableReturnsTrue — idempotency test; verifies the existing-table early-return path still works

Tests run against all CI drivers (SQLite, MySQL, PostgreSQL).

Breaking change assessment

No public API signature or return type changed. The method already returned bool. When a table is absent the method previously threw; now it correctly proceeds to CREATE TABLE and returns true on success. Safe for patch-level consumers.

AI Disclosure

This fix was developed using an AI-assisted workflow. AI agents (Claude) wrote the code, tests, and initial code review under the direction of the project maintainer (@opengeek), who reviewed the final diff, validated the approach, and takes responsibility for the submission.

Contributors

Reported by the issue author. Community comment by @wshawn provided additional context.

The SELECT COUNT(*) table-existence probe in all four driver managers
threw an uncaught PDOException when the table did not exist and PDO was
in ERRMODE_EXCEPTION mode. Wrapping the probe in try/catch allows the
method to proceed to CREATE TABLE as intended.

Closes modxcms#207.
@opengeek opengeek force-pushed the fix/207-mysql8-container branch from 9204ade to dd9e9fc Compare April 2, 2026 21:38
@opengeek opengeek merged commit 2b1606e into modxcms:3.x Apr 2, 2026
15 checks passed
@opengeek opengeek deleted the fix/207-mysql8-container branch April 2, 2026 21:41
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.

[bug] don't work xPDOManager->createObjectContainer() in MySQL > 8

2 participants