Skip to content

Conversation

patrykgruszka
Copy link
Member

@patrykgruszka patrykgruszka commented Jul 9, 2025

Q A
Bug fix? (use the a.b branch) ✔️
New feature/enhancement? (use the a.x branch)
Deprecations?
BC breaks? (use the c.x branch)
Automated tests included?
Related user documentation PR URL mautic/user-documentation#...
Related developer documentation PR URL mautic/developer-documentation-new#...
Issue(s) addressed Fixes #14230

Description

This PR addresses an issue where the executeQuery method was used for data modification (write) operations in the codebase. According to Doctrine DBAL documentation, executeQuery should only be used for data retrieval, while executeStatement must be used for any operation that modifies data (e.g., INSERT, UPDATE, DELETE, DDL). Using executeQuery for writes can cause replication issues in primary-replica setups, potentially leading to data inconsistencies and errors such as duplicate keys.

What was changed:

  • Replaced all instances of executeQuery used for data modification with executeStatement.
  • Ensured that all write operations now use the correct method, preventing accidental writes to replica databases.

📋 Steps to test this PR:

1. Test with replication enabled:

  • Set up a primary-replica database configuration by adding a replica database host to your local.php config using the db_host_ro key.
  • Perform actions in Mautic that trigger data modification (e.g., run a campaign, anonymize IP addresses, remove event logs):
  • Create and run a campaign
  • Generate the campaign summary - ddev exec php bin/console mautic:campaign:summarize
  • Delete the campaign
  • Delete unused IP addresses - ddev exec php bin/console mautic:unusedip:delete
  • Anonymize all IP adderesses - ddev exec php bin/console mautic:anonymize:ip
  • Verify that all data modification queries are executed on the primary database and not the replica.
  • Check for the absence of replication errors (such as duplicate key errors) in your database logs.
  • Confirm that data remains consistent between the primary and replica databases.

2. Test without replication (single database):

  • Use a standard single-database setup without configuring a replica in local.php.
  • Perform actions in Mautic that trigger data modification (e.g., run a campaign, anonymize IP addresses, remove event logs):
  • Create and run a campaign
  • Generate the campaign summary - ddev exec php bin/console mautic:campaign:summarize
  • Delete the campaign
  • Delete unused IP addresses - ddev exec php bin/console mautic:unusedip:delete
  • Anonymize all IP adderesses - ddev exec php bin/console mautic:anonymize:ip
  • Ensure that all affected features work as expected and that there are no errors or regressions in functionality.
  • Confirm that data is correctly updated in the database.

@patrykgruszka patrykgruszka marked this pull request as draft July 9, 2025 13:12
Copy link

codecov bot commented Jul 9, 2025

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.83%. Comparing base (28985fb) to head (cfc19e0).
⚠️ Report is 8 commits behind head on 6.0.

Files with missing lines Patch % Lines
app/bundles/PluginBundle/Bundle/PluginDatabase.php 0.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                6.0   #15199   +/-   ##
=========================================
  Coverage     64.83%   64.83%           
  Complexity    34784    34784           
=========================================
  Files          2278     2278           
  Lines        103875   103875           
=========================================
  Hits          67344    67344           
  Misses        36531    36531           
Files with missing lines Coverage Δ
...s/CampaignBundle/Entity/LeadEventLogRepository.php 87.16% <100.00%> (ø)
...undles/CampaignBundle/Entity/SummaryRepository.php 95.45% <100.00%> (ø)
...p/bundles/CoreBundle/Entity/AuditLogRepository.php 68.70% <100.00%> (ø)
.../bundles/CoreBundle/Entity/IpAddressRepository.php 69.56% <100.00%> (ø)
...undle/EventListener/MigrationCommandSubscriber.php 100.00% <100.00%> (ø)
...eBundle/EventListener/OptimisticLockSubscriber.php 92.30% <100.00%> (ø)
app/bundles/InstallBundle/Helper/SchemaHelper.php 70.50% <100.00%> (ø)
...undles/LeadBundle/Entity/CompanyLeadRepository.php 69.16% <100.00%> (ø)
app/bundles/WebhookBundle/Entity/LogRepository.php 49.09% <100.00%> (ø)
app/bundles/PluginBundle/Bundle/PluginDatabase.php 13.15% <0.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@patrykgruszka patrykgruszka marked this pull request as ready for review July 9, 2025 13:50
Copy link
Member

@kuzmany kuzmany left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me

@RCheesley RCheesley linked an issue Jul 10, 2025 that may be closed by this pull request
1 task
@RCheesley RCheesley added T3 Hard difficulty to fix (issue) or test (PR) ready-to-test PR's that are ready to test email Anything related to email labels Jul 10, 2025
@RCheesley RCheesley moved this to 🦸🏻 Needs 2 tests in Open Source Fridays Jul 10, 2025
@RCheesley RCheesley added the code-review-passed PRs which have passed code review label Jul 10, 2025
@RCheesley RCheesley moved this to Needs review in Quality Sprint 2025 Jul 10, 2025
@RCheesley RCheesley added this to the 6.0.4 milestone Jul 10, 2025
@RCheesley
Copy link
Member

@mabumusa1 any chance you could test this? I think you used to work a lot with replicas but not sure if you've still got active test instances.

Copy link
Member

@escopecz escopecz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍 Thanks!

I also executed the commands with no issues.

@escopecz escopecz moved this from Needs review to Done in Quality Sprint 2025 Jul 10, 2025
@escopecz escopecz self-assigned this Jul 10, 2025
Copy link

@escopecz escopecz added ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged user-testing-passed PRs which have been successfully tested by the required number of people. and removed ready-to-test PR's that are ready to test labels Jul 10, 2025
@escopecz escopecz merged commit fa0653e into mautic:6.0 Jul 11, 2025
19 checks passed
@github-project-automation github-project-automation bot moved this from 🦸🏻 Needs 2 tests to 🥳 Done in Open Source Fridays Jul 11, 2025
@RCheesley RCheesley added the bug Issues or PR's relating to bugs label Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues or PR's relating to bugs code-review-passed PRs which have passed code review email Anything related to email ready-to-commit PR's with 2 successful tests, 1 approval, automated tests and docs and is ready to be merged T3 Hard difficulty to fix (issue) or test (PR) user-testing-passed PRs which have been successfully tested by the required number of people.
Projects
Status: 🥳 Done
Development

Successfully merging this pull request may close these issues.

Incorrect Usage of executeQuery for Data Modification
4 participants