Flask signals: why is it not ok to modify data on signal?

Flask documentations says:

Also keep in mind that signals are intended to notify subscribers and should not encourage subscribers to modify data

I am wondering, why is so?

I'm using Flask-User library, and I would like to set some default fields for user when a user registers(eg set displayname to be equal to username) and then update the db. Flask-User sends user_registered signal when user registers. Why is it a bad idea to subscribe to the signal, and update db in it?


It is the over-round solution. I guess I am strong Drupal/PHP developer. Up to the 7-th version everything was built using hooks - signals(Flask). The project becomes a mess when everything is built on hooks. It is a quick process but dangerous. Signals are designed to be used as the observer pattern , It likes to events. It is the main idea. But when we able to update the context, subjects. It likes to the chain responsibility . The main problem is the chain. So if one item fails the anothers receive the wrong state. It is the main problem. Sometimes it is difficult to find a culprit who fails. Because we have different signals from different subjects these modify the common scope.

You can extend almost everywhere but you should not change data. To extend right you should use clean OOP solutions.

Sometimes we need to change some logic. So we need define a basket what we need change. In Drupal 8 we use Dependency Injection Containers - Services. Services are described in separated files. So we able changes relations and injections.

There is the interesting library - https://pypi.python.org/pypi/Flask-Injector .

链接地址: http://www.djcxy.com/p/22480.html

上一篇: Angular JS:在另一个ng中包含部分HTML

下一篇: 烧瓶信号:为什么修改信号数据不好?