Repository: dynaconf/dynaconf

Issue:
[bug] dynaconf 3.2.2 broke dynaconf_include when combined with root_path (still broken on 3.2.4)
**Describe the bug**

Files listed in the `dynaconf_include` array inside my main toml file aren't being loaded after dynaconf 3.2.2. In 3.2.1 works like a charm.

**To Reproduce**
Steps to reproduce the behavior:

1. Having the following folder structure

<details>
<summary> Project structure </summary>

```bash
C:.
│   README.md
│
├───dynaconf_experiment
│       __main__.py
│
└───etc
        .env
        file_1.toml
        file_2.toml
        mafile.toml
```
</details>

2. Having the following config files:

<details>
<summary> Config files </summary>

**etc/.env**
```bash
SETTINGS_FILE_FOR_DYNACONF=mafile.toml
```

and

**etc/mafile.toml**
```toml
dynaconf_include = [
    "file_2.toml",
]

name = "peter"
```

and

**etc/file_2.toml**
```toml
age = 6
```

</details>

3. Having the following app code:

<details>
<summary> Code </summary>

**dynaconf_experiment/__main__.py**
```python
from os import getcwd

from dynaconf import Dynaconf

config = Dynaconf(
    dotenv_override=True,
    encoding="utf-8",
    environments=False,
    envvar_prefix=False,  # won't use a prefix at all
    load_dotenv=True,  # .env file is automatically detected and loaded
    root_path="etc",
)

print("Hello!")
print(getcwd())

print(config.dynaconf_include)
print(config.name)
print(config.age)

```

</details>

4. Executing under the following environment

<details>
<summary> Execution </summary>

```bash
pip install dynaconf==3.2.1
py dynaconf_experiment  # will work fine

pip install dynaconf==3.2.2
py dynaconf_experiment  # will fail

pip install dynaconf==3.2.4
py dynaconf_experiment  # will fail
```
</details>

**Current behavior**

![image](https://github.com/dynaconf/dynaconf/assets/37153467/7a726970-b0e6-46d4-b7a5-c898b2999398)


**Expected behavior**

Works like 3.2.1 did:
![image](https://github.com/dynaconf/dynaconf/assets/37153467/fdc2cd9c-db5f-427b-8443-1f3ae74be8f7)



A clear and concise description of what you expected to happen.

**Environment (please complete the following information):**
 - Python: 3.11.6.
 - OS: Windows 10.
 - Frameworks in use (Flask, Django? versions..): Fails with no framework at all.

**Additional context**
Repository with the code and files: https://github.com/jmwielandt/dynaconf-experiment

No moar context exists.



Discussion:
I'll leave some notes for myself for when I can continue this investigation.

- That was introduced [here](https://github.com/dynaconf/dynaconf/pull/987/files)
- it is related to the use of a relative `root_path`. When using absolute `root_path` the error is not raised

Resolving patch:
diff --git a/dynaconf/base.py b/dynaconf/base.py
--- a/dynaconf/base.py
+++ b/dynaconf/base.py
@@ -1256,14 +1256,10 @@ def load_file(
                     filepath = os.path.join(root_dir, str(_filename))
 
                 paths = [
-                    p
-                    for p in sorted(glob(filepath, root_dir=self._root_path))
-                    if ".local." not in p
+                    p for p in sorted(glob(filepath)) if ".local." not in p
                 ]
                 local_paths = [
-                    p
-                    for p in sorted(glob(filepath, root_dir=self._root_path))
-                    if ".local." in p
+                    p for p in sorted(glob(filepath)) if ".local." in p
                 ]
 
                 # Handle possible *.globs sorted alphanumeric


Test patch:
diff --git a/tests_functional/issues/1025_include-with-root-path/Makefile b/tests_functional/issues/1025_include-with-root-path/Makefile
new file mode 100644
--- /dev/null
+++ b/tests_functional/issues/1025_include-with-root-path/Makefile
@@ -0,0 +1,4 @@
+.PHONY: test
+
+test:
+	pytest -sv app.py
diff --git a/tests_functional/issues/1025_include-with-root-path/app.py b/tests_functional/issues/1025_include-with-root-path/app.py
new file mode 100644
--- /dev/null
+++ b/tests_functional/issues/1025_include-with-root-path/app.py
@@ -0,0 +1,47 @@
+"""
+[bug] dynaconf 3.2.2 broke dynaconf_include when combined with root_path
+
+https://github.com/dynaconf/dynaconf/issues/1025
+"""
+from __future__ import annotations
+
+import os
+from textwrap import dedent
+
+from dynaconf import Dynaconf
+
+
+def create_file(name, data):
+    with open(name, "w") as file:
+        file.write(dedent(data))
+
+    return name
+
+
+def test_1025(tmp_path):
+    os.chdir(tmp_path)
+    basedir = tmp_path / "etc"
+    basedir.mkdir()
+    f1 = create_file(
+        basedir / "f1.toml",
+        """
+        dynaconf_include = [
+            "f2.toml",
+        ]
+
+        name = "peter"
+        """,
+    )
+    create_file(
+        basedir / "f2.toml",
+        """
+        age = 6
+        """,
+    )
+
+    settings = Dynaconf(
+        settings_file=str(f1.absolute()),
+        root_path=basedir.name,
+    )
+    assert settings.name
+    assert settings.age