### Apache Airflow version

2.7.1

### What happened

Unable to retrieve logs for task inside task group inside mapped task group.
Got `404 "TaskInstance not found"` in network requests

### What you think should happen instead

_No response_

### How to reproduce

```
from datetime import datetime
from airflow import DAG
from airflow.decorators import task, task_group
from airflow.operators.bash import BashOperator
from airflow.utils.task_group import TaskGroup

with DAG("mapped_task_group_bug", schedule=None, start_date=datetime(1970, 1, 1)):
    @task
    def foo():
        return ["a", "b", "c"]


    @task_group
    def bar(x):
        with TaskGroup("baz"):
            # If child task group exists, logs 404
            #  "TaskInstance not found"
            # http://localhost:8080/api/v1/dags/mapped_task_group_bug/dagRuns/manual__2023-09-21T22:31:56.863704+00:00/taskInstances/bar.baz.bop/logs/2?full_content=false
            # if it is removed, logs appear
            BashOperator(task_id="bop", bash_command="echo hi $x", env={"x": x})


    bar.partial().expand(x=foo())
```

### Operating System

debian 11 / `astro dev start`

### Versions of Apache Airflow Providers

_No response_

### Deployment

Astronomer

### Deployment details

_No response_

### Anything else

_No response_

### Are you willing to submit PR?

- [ ] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)

downstream = request.form.get("downstream") == "true"
        future = request.form.get("future") == "true"
        past = request.form.get("past") == "true"
        recursive = request.form.get("recursive") == "true"
        only_failed = request.form.get("only_failed") == "true"
        task_ids: list[str | tuple[str, int]] = []
        end_date = execution_date if not future else None
        start_date = execution_date if not past else None
        locked_dag_run_ids: list[int] = []
        if group_id is not None:
            task_group_dict = dag.task_group.get_task_group_dict()
            task_group = task_group_dict.get(group_id)
            if task_group is None:
                return redirect_or_json(
                    origin, msg=f"TaskGroup {group_id} could not be found", status="error", status_code=404
                )
            task_ids = task_ids_or_regex = [t.task_id for t in task_group.iter_tasks()]
            
            
            dag_runs_query = select(DagRun.id).where(DagRun.dag_id == dag_id).with_for_update()
            if start_date is None and end_date is None:
                dag_runs_query = dag_runs_query.where(DagRun.execution_date == start_date)
            else:
                if start_date is not None:
                    dag_runs_query = dag_runs_query.where(DagRun.execution_date >= start_date)
                if end_date is not None:
                    dag_runs_query = dag_runs_query.where(DagRun.execution_date <= end_date)
            locked_dag_run_ids = session.scalars(dag_runs_query).all()
        elif task_id:
            if map_indexes is None: