code: def test_custom_query_class(app: Flask) -> None:
      class CustomQuery(Query):
          pass
  
      db = SQLAlchemy(app, query_class=CustomQuery)
  
      class Parent(db.Model):
          id = sa.Column(sa.Integer, primary_key=True)
          children1 = db.relationship(
              "Child", backref="parent1", lazy="dynamic"
          )
  
      class Child(db.Model):
          id = sa.Column(sa.Integer, primary_key=True)
          parent_id = sa.Column(sa.ForeignKey(Parent.id))  # type: ignore[var-annotated]
          parent2 = db.relationship(
              Parent,
              backref=db.backref(
                  "children2", lazy="dynamic", viewonly=True
              ),
              viewonly=True,
          )
  
      p = Parent()
      assert type(Parent.query) is CustomQuery
      assert isinstance(p.children1, CustomQuery)
      assert isinstance(p.children2, CustomQuery)
      assert isinstance(db.session.query(Child), CustomQuery)
  
file_path: flask-sqlalchemy/tests/test_legacy_query.py
imports: from __future__ import annotations
  import typing
  import warnings
  import pytest
  import sqlalchemy
  import sqlalchemy.exc
  from flask import Flask
  from werkzeug.exceptions import NotFound
  from flask_sqlalchemy import SQLAlchemy
  from flask_sqlalchemy.query import Query
label_desc: Use image node_id 7 for calling a global function with example usage: test_custom_query_class(app) without return types