### Apache Airflow version

2.6.0

### What happened

Hi, I'm unable to remove DagRun and TaskInstance when they have note attached.



### What you think should happen instead

Should be able to remove DagRuns or TaskInstances with or without notes.
Also note should be removed when parent entity is removed.

### How to reproduce

1. Create note in DagRun or TaskInstance
2. Try to remove the row that note has been added by clicking delete record icon. This will display alert in the UI `General Error <class 'AssertionError'>`
3. Select checkbox DagRun containing note, click `Actions` dropdown and select `Delete`. This won't display anything in the UI.

### Operating System

OSX 12.6

### Versions of Apache Airflow Providers

apache-airflow-providers-cncf-kubernetes==5.2.2
apache-airflow-providers-common-sql==1.3.4
apache-airflow-providers-ftp==3.3.1
apache-airflow-providers-http==4.2.0
apache-airflow-providers-imap==3.1.1
apache-airflow-providers-postgres==5.4.0
apache-airflow-providers-sqlite==3.3.1

### Deployment

Virtualenv installation

### Deployment details

Deployed using Postgresql 13.9 and sqlite 3

### Anything else

DagRun deletion Log
```
[2023-05-01T13:06:42.125+0700] {interface.py:790} ERROR - Delete record error: Dependency rule tried to blank-out primary key column 'dag_run_note.dag_run_id' on instance '<DagRunNote at 0x1125afa00>'
Traceback (most recent call last):
  File "/opt/airflow/.venv/lib/python3.10/site-packages/flask_appbuilder/models/sqla/interface.py", line 775, in delete
    self.session.commit()
  File "<string>", line 2, in commit
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1451, in commit
    self._transaction.commit(_to_root=self.future)
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 829, in commit
    self._prepare_impl()
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl
    self.session.flush()
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3446, in flush
    self._flush(objects)
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3585, in _flush
    with util.safe_reraise():
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3546, in _flush
    flush_context.execute()
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 577, in execute
    self.dependency_processor.process_deletes(uow, states)
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/dependency.py", line 552, in process_deletes
    self._synchronize(
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/dependency.py", line 610, in _synchronize
    sync.clear(dest, self.mapper, self.prop.synchronize_pairs)
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/sync.py", line 86, in clear
    raise AssertionError(
AssertionError: Dependency rule tried to blank-out primary key column 'dag_run_note.dag_run_id' on instance '<DagRunNote at 0x1125afa00>'
```

TaskInstance deletion Log

```
[2023-05-01T13:06:42.125+0700] {interface.py:790} ERROR - Delete record error: Dependency rule tried to blank-out primary key column 'task_instance_note.task_id' on instance '<TaskInstanceNote at 0x1126ba770>'
Traceback (most recent call last):
  File "/opt/airflow/.venv/lib/python3.10/site-packages/flask_appbuilder/models/sqla/interface.py", line 775, in delete
    self.session.commit()
  File "<string>", line 2, in commit
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 1451, in commit
    self._transaction.commit(_to_root=self.future)
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 829, in commit
    self._prepare_impl()
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 808, in _prepare_impl
    self.session.flush()
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3446, in flush
    self._flush(objects)
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3585, in _flush
    with util.safe_reraise():
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/session.py", line 3546, in _flush
    flush_context.execute()
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 456, in execute
    rec.execute(self)
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/unitofwork.py", line 577, in execute
    self.dependency_processor.process_deletes(uow, states)
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/dependency.py", line 552, in process_deletes
    self._synchronize(
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/dependency.py", line 610, in _synchronize
    sync.clear(dest, self.mapper, self.prop.synchronize_pairs)
  File "/opt/airflow/.venv/lib/python3.10/site-packages/sqlalchemy/orm/sync.py", line 86, in clear
    raise AssertionError(
AssertionError: Dependency rule tried to blank-out primary key column 'task_instance_note.task_id' on instance '<TaskInstanceNote at 0x1126ba770>'
```

### Are you willing to submit PR?

- [X] 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)

from airflow.settings import _ENABLE_AIP_52, TIMEZONE
from airflow.stats import Stats
from airflow.ti_deps.dep_context import DepContext
from airflow.ti_deps.dependencies_deps import REQUEUEABLE_DEPS, RUNNING_DEPS
from airflow.ti_deps.dependencies_states import RUNNABLE_STATES
from airflow.ti_deps.deps.base_ti_dep import TIDepStatus
from airflow.ti_deps.deps.trigger_rule_dep import TriggerRuleDep, _UpstreamTIStates
from airflow.utils import timezone
from airflow.utils.db import merge_conn
from airflow.utils.module_loading import qualname
from airflow.utils.session import create_session, provide_session
from airflow.utils.state import State, TaskInstanceState
from airflow.utils.task_group import TaskGroup
from airflow.utils.types import DagRunType
from airflow.utils.xcom import XCOM_RETURN_KEY
from airflow.version import version
from tests.models import DEFAULT_DATE, TEST_DAGS_FOLDER
from tests.test_utils import db
from tests.test_utils.config import conf_vars
from tests.test_utils.db import clear_db_connections, clear_db_runs
from tests.test_utils.mock_operators import MockOperator
@pytest.fixture
def test_pool():
    with create_session() as session:
        test_pool = Pool(pool="test_pool", slots=1)
        session.add(test_pool)
        session.flush()
        yield test_pool
        session.rollback()
class CallbackWrapper: