Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index even if i rollback transaction #1917

Open
Zarlokh opened this issue Jul 5, 2023 · 2 comments
Open

Index even if i rollback transaction #1917

Zarlokh opened this issue Jul 5, 2023 · 2 comments

Comments

@Zarlokh
Copy link

Zarlokh commented Jul 5, 2023

Package Version : v6.2.0
PHP version : 8.2.5
doctrine/dbal version : 3.6.2
Symfony version : 5.4.22
Elastica conf :

fos_elastica:
    clients:
        default: { host: "%env(ELASTICSEARCH_HOST)%", port: '%env(ELASTICSEARCH_PORT)%' }
    indexes:
        bubbles:
            ...
        unavailabilities:
            ...
        orders:
            properties:
               ...
            persistence:
                driver: orm
                model: App\Entity\Order\Order
                listener:
                    defer: true
                provider:
                    query_builder_method: getQueryBuilderForElasticaPopulate

With this conf, if i run this code

        $entityManager->beginTransaction();
        $order = new Order();
        $order->setCode('test123456789');
        $entityManager->persist($order);
        $entityManager->flush();
        $entityManager->rollback();

My order is not create in my database but if i check my elasticsearch, i can find this order
image

Now, if i go to my order list page, i have an error because Elastica cannot find this order in my database
So, how can i index my entity only if a transaction is committed and not rollbacked ? (i see nothing about that in closed or opened issues and nothing about it in any site like stackoverflow. Did i miss something ?)

Thanks for helping

@timmtim
Copy link

timmtim commented Oct 3, 2023

@Zarlokh did you find a solution for this issue. I've encountered the exact same problem.

@Zarlokh
Copy link
Author

Zarlokh commented Oct 3, 2023

Hi @timmtim
I duplicate the Listener used by FOSElastica to fix it.
I create an array with entities in case of a transaction is running
I create a decorator on EntityManager to dispatch a custom event on rollback method and commit to do something on Listener (remove entities from array or push it on elastic if it is not defer etc...)
Be careful about nested transaction

I'm not very happy about my fix but I need it to avoid any error on my app
I'm waiting for an official fix :/

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

No branches or pull requests

2 participants