What does _db used for in a django Model Manager
While trying to create a custom QuerySet and a custom Manager for a django Model I stumbled upon the documentation sections 1 and 2 that use the manager's _db property and i would like to understand what does this property do and why is it necessary to use it when overriding the get_queryset method.
I read the code in the django repo and did some django db queries locally with different databases and printed the _db property but it seems it is always None.
So, what is the use for it and why is it important to handle it as per doc 2?
As briefly described in that documentation you link to:
If you’re overriding
get_queryset()on your manager, be sure to either call the method on the parent (usingsuper()) or do the appropriate handling of the_dbattribute on the manager (a string containing the name of the database to use).https://docs.djangoproject.com/en/6.0/topics/db/multi-db/#using-get-queryset-with-multiple-databases
You should start reading at the top of that page. It's about support for multiple databases. The _db attribute may contain the name of the database that was passed via using='dbname'/.using('dbname') somewhere, and you need to pass that on properly if you don't want it to fall back to the default database.