Skip to content

Remove in_factory_bot_create?

Omar Qunsul requested to merge 425220-in-factory-bot-created-removal-2 into master

What does this MR do and why?

Addressing: #425220 (closed)

What has changed?

The goal of this MR is to remove the hacky method self.in_factory_bot_create? which looks into whether a FactoryBot object is in the process of being created to suppress the PreventCrossDatabaseModification.

This MR changes this approach to handle two cases:

  1. (no change) Objects that are built using :build FactoryBot Strategy. Nothing changed on the implementation. The objects are marked as built by FactoryBot so that when they are saved later, we temporarily ignore their table.

  2. (changed in this MR) Objects that are built using :create Strategy increase some counter in the current Thread, which marks how many objects are in the process of being created. The PreventCrossDatabaseModification is temporarily suppressed when some object is being created.

What is PreventCrossDatabaseModification Query Analyzer?

GitLab can run on more than 1 database. And that's the case on GitLab.com at the moment. You can read about it here. The Query Analyzer PreventCrossDatabaseModification goal is to make sure we don't access more than 1 database within the same database transaction to avoid problems resulting from committing 1 transaction and aborting the other. Or having a database transaction open for long time while writing to the other database.

Why is FactoryBot Gem updated in this MR?

Because I needed to include this fix for ActiveSupport::Notifications https://github.com/thoughtbot/factory_bot/commit/1b81d5dc258e5f1ad25c5109cb4bf3f6be83deb4

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #425220 (closed)

Edited by Omar Qunsul

Merge request reports