Repository: dynaconf/dynaconf

Issue:
[bug] Updating app.config variable does not set a new value
**Describe the bug**
In a flask appusing the flaskdynaconf extension updating a app.config variables value after the calling `FlaskDynaconf(app)` does not actually update the value. Is this the expected behavior from flaskdynaconf?

**To Reproduce**
Steps to reproduce the behavior:
```

"""
$ pip install pytest dynaconf flask
# run the tests using pytest and note the test failure
"""
import pytest
from dynaconf import FlaskDynaconf, settings
from flask import Flask


def test_manually_overriding_flask_conf_settings():
    app = Flask(__name__)

    # initialize dynaconf settings instance with a message value
    settings["MESSAGE"] = "hello"

    # assert that the value is set correctly
    assert settings["MESSAGE"] == "hello"

    # tie the dyanconf settings and flask app config together
    FlaskDynaconf(app, dynaconf_instance=settings)

    # assert that the message value is unchanged
    assert app.config["MESSAGE"] == "hello"
    assert settings.MESSAGE == "hello"

    # change the value manually via dynaconf settings instance
    settings["MESSAGE"] = "bye"

    # assert that the value is changed
    assert settings["MESSAGE"] == "bye"
    assert app.config["MESSAGE"] == "bye"

    # change the value manually via app.config
    app.config["MESSAGE"] = "hi"

    # assert that the value is changed
    assert app.config["MESSAGE"] == settings["MESSAGE"] == "hi"
    #  above fails because app.config does not update the message variable
    #  to the new value
```
1. Having the following folder structure

<!-- Describe or use the command `$ tree -v` and paste below -->

<details>
<summary> Project structure </summary>

```bash

# /path/
# ...../folder/...
# please provide your folder structure here

```
</details>

2. Having the following config files:

<!-- Please adjust if you are using different files and formats! -->

<details>
<summary> Config files </summary>

**/path/.env**
```bash
Your .env content here
```

and

**/path/settings.toml**
```toml
[default]
```

</details>

3. Having the following app code:

<details>
<summary> Code </summary>

**/path/src/app.py**
```python
from dynaconf import settings
...
```

</details>

4. Executing under the following environment

<details>
<summary> Execution </summary>

```bash
# other commands and details?
# virtualenv activation?

$ python above_tests.py
```

</details>

**Expected behavior**
A clear and concise description of what you expected to happen.
I expected that updating a variable in app.config would stick and update its value.

**Debug output**

<details>
<summary> Debug Output </summary>

```bash

export `DEBUG_LEVEL_FOR_DYNACONF=DEBUG` reproduce your problem and paste the output here
========================================================================================================================= test session starts ==========================================================================================================================
platform win32 -- Python 3.6.3, pytest-4.5.0, py-1.8.0, pluggy-0.11.0
rootdir: C:\DevTools\Projects\playground
collected 1 item                                                                                                                                                                                                                                                        

test_for_dynaconf.py F                                                                                                                                                                                                                                            [100%]

=============================================================================================================================== FAILURES ===============================================================================================================================
_____________________________________________________________________________________________________________ test_manually_overriding_flask_conf_settings _____________________________________________________________________________________________________________

    def test_manually_overriding_flask_conf_settings():
        app = Flask(__name__)
    
        # initialize dynaconf settings instance with a message value
        settings["MESSAGE"] = "hello"
    
        # assert that the value is set correctly
        assert settings["MESSAGE"] == "hello"
    
        # tie the dyanconf settings and flask app config together
        FlaskDynaconf(app, dynaconf_instance=settings)
    
        # assert that the message value is unchanged
        assert app.config["MESSAGE"] == "hello"
        assert settings.MESSAGE == "hello"
    
        # change the value manually via dynaconf settings instance
        settings["MESSAGE"] = "bye"
    
        # assert that the value is changed
        assert settings["MESSAGE"] == "bye"
        assert app.config["MESSAGE"] == "bye"
    
        # change the value manually via app.config
        app.config["MESSAGE"] = "hi"
    
        # assert that the value is changed
>       assert app.config["MESSAGE"] == settings["MESSAGE"] == "hi"
E       AssertionError: assert 'bye' == 'hi'
E         - bye
E         + hi

test_for_dynaconf.py:38: AssertionError
```

</details>

**Environment (please complete the following information):**
 - Windows 10(Version 10.0.15063 Build 15063)
 - Dynaconf Version 2.0.1
 - Flask Version 1.0.2

**Additional context**
Add any other context about the problem here.



Discussion:
@rochacbruno Just curious, is this a bug or intended behavior? 
@mketiku this seems to be a bug, dynaconf.LazySettings is bound to `flask.config` as its `config_class` attribute. Usually in dynaconf we do `settings.set('key', value)` and that may be the problem.

can you try `app.config.set('key', value)` and see if it works?

If so then the fix is to implement a `__setitem__` method.

Resolving patch:
diff --git a/dynaconf/contrib/flask_dynaconf.py b/dynaconf/contrib/flask_dynaconf.py
--- a/dynaconf/contrib/flask_dynaconf.py
+++ b/dynaconf/contrib/flask_dynaconf.py
@@ -145,6 +145,12 @@ def __getitem__(self, key):
         """
         return self.get(key)
 
+    def __setitem__(self, key, value):
+        """
+        Allows app.config['key'] = 'foo'
+        """
+        return self._settings.__setitem__(key, value)
+
     def __getattr__(self, name):
         """
         First try to get value from dynaconf then from Flask
diff --git a/example/issues/194_flask_config/app.py b/example/issues/194_flask_config/app.py
new file mode 100644
--- /dev/null
+++ b/example/issues/194_flask_config/app.py
@@ -0,0 +1,23 @@
+from flask import Flask
+
+from dynaconf import FlaskDynaconf
+from dynaconf import settings
+
+
+app = Flask(__name__)
+
+settings["MESSAGE"] = "hello"
+assert settings["MESSAGE"] == "hello"
+
+FlaskDynaconf(app, dynaconf_instance=settings)
+
+assert app.config["MESSAGE"] == "hello"
+
+app.config.set("MESSAGE", "bye")
+
+assert app.config["MESSAGE"] == "bye"
+
+
+app.config["MESSAGE"] = "bazinga"
+
+assert app.config["MESSAGE"] == "bazinga"


Test patch: