-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
AfterUpdate subscriber bug #1705
Comments
It is expected. If something is failing in AfterUpdate transaction should be reverted, it is by design. |
@pleerock so, is there any way to notify listeners that something was updated or inserted? |
Listeners and subscribers already do it. |
@pleerock they are notified before transaction is commited. I need to notify listeners when the data is already in the database. How to do it proprerly? |
Depend of your needs. You can call your method without listeners simply after you call But I guess you need a data that inserted but not yet committed, in this case you need to use same |
No, I need a confirmation that data is updated AND it is in the database. |
Thats what I was talking about. You need to use same |
I think this behaviour should be documented. Coming from a framework like Rails, the callbacks happen after the transaction has been committed. |
I don't get it. Well, in my ElasticSearch update function I use a parent of this entity, and it updates that parent (and some relations, including my current entity) but the values I get in that process are the old ones. Even if I call entity.reload(). Even if I call "await repository.findOne(entity.id)" to re-assign the entity value. My thinking is that it's not only undocumented in the docs, but its also missdocumented according to the TypeScript definition. For a solution, I ended up overriding the save() method for my entity. async save() : Promise<this> {
await super.save();
await this.updateElasticSearch();
return this;
} It seems to work so far. |
I don't understand why this has been closed. I believe this is still a needed feature. As I see it, the two behaviors should be supported:
Is there any plan to support this in the future? I see it was requested at #743 too? are PR implementing this welcome? @didac-wh, did overwriting |
@cjuega have you tried to use a subscriber as described here: #3563 (comment) ? |
@pleerock Wouldn't it be more convenient to introduce a |
any updated about this ? would be it possible to have the same |
Can this please be documented in the relevant documentation. It's not super clear on how to monitor this. For reference when people find them selves here async afterUpdate(entity: UpdateEvent<Master>) {
var x = await entity.manager.find(Master)
console.log(x)
} |
UpdateEvent.entity is undefined in afterUpdate. How does one get the updated entity in the subscriber? |
I'm not sure if this is the best solution, but for anyone else who comes across this issue, this is what fixed it for us. We just added the following lines at the beginning of the await event.queryRunner.commitTransaction();
await event.queryRunner.startTransaction(); In our case, the issue was that we were sending IDs to a queue to trigger search indexing, and the queue was being processed before the transaction was committed (though I found that surprising). So data in our search index was always one step behind the actual data. For most use cases I can imagine, I think the naming of the subscriber is misleading. To me, |
Still not fixed |
It's not fixed and the documentation does not explain the relation between transactions and subscription events. |
This issue still exists. It would be nice to have an event that emit after the transaction is committed to cater to rest of use cases as well |
Posting to agree that the name and behavior of this event is unintuitive and not well documented. An event after the transaction commits would be hugely helpful in many circumstances. |
Issue type:
[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[ ]
mongodb
[ ]
mssql
[ ]
mysql
/mariadb
[ ]
oracle
[x]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
websql
TypeORM version:
[ ]
latest
[ ]
@next
[x]
0.1.9
(or put your version here)Steps to reproduce or a small repository showing the problem:
@AfterUpdate
decorator to it.getRepository(Entity).save()
).Expected behaviour:
When method with
@AfterUpdate
runs, I can get updated entity from database.Actual behaviour:
Here's what actually happens:
executing query: START TRANSACTION
)UPDATE
query is executed (executing query: UPDATE "entity" SET "something"=$1 WHERE "id"=$2 -- PARAMETERS: [1,2]
)@AfterUpdate
is called.So, when
@AfterUpdate
method is called, entity in the database has not been updated yet. Therefore, I can not get updated entities from the database.The text was updated successfully, but these errors were encountered: