Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.
Python aicode-complexitycode-healthcode-intelligencecode-qualitydead-codedeveloper-toolsdocumentationgit-analyticsmcpopen-sourcepythonrefactoringstatic-analysistechnical-debt
{"result":{"mode":"search","query":"why is QuerySet lazy","decisions":[],"reason":"No decision record covers this question. The rationale comments below carry its terms. They are quoted from the code and its history, not a ruling: read them as evidence, not as the recorded reason.","code_rationale":[{"path":"django/forms/models.py","lines":[1564,1570],"comment":"Otherwise, execute the QuerySet in self.queryset to determine the choices dynamically. Return a fresh ModelChoiceIterator that has not been consumed. Note that we're instantiating a new ModelChoiceIterator *each* time _get_choices() is called (and, thus, each time self.choices is accessed) so that we can ensure the QuerySet has not been consumed. This construct might look complicated but it allows for lazy evaluation of the queryset.","provenance":"extracted_rationale","evidence_refs":[{"id":"ev_f777c9cdffdc0028cce6","repository":"default","kind":"file_content","path":"django/forms/models.py","line":1564,"content_id":"f4ea3d71bc2e4029ca23","range":[1564,1570],"provenance":"extracted_rationale","source":"live_code_rationale","source_kind":"code_comment","verification":"exact","verification_basis":"live"}]},{"path":"django/core/paginator.py","lines":[320,321],"comment":"The object_list is converted to a list so that if it was a QuerySet it won't be a database hit per __getitem__.","provenance":"extracted_rationale","evidence_refs":[{"id":"ev_7908cb0a3caa60de169b","repository":"default","kind":"file_content","path":"django/core/paginator.py","line":320,"content_id":"f179e54b0ab819dc1b05","range":[320,321],"provenance":"extracted_rationale","source":"live_code_rationale","source_kind":"code_comment","verification":"exact","verification_basis":"live"}]},{"path":"django/db/models/manager.py","lines":[158,163],"comment":"We can't proxy this method through the `QuerySet` like we do for the rest of the `QuerySet` methods. This is because `QuerySet.all()` works by creating a \"copy\" of the current queryset and in making said copy, all the cached `prefetch_related` lookups are lost. See the implementation of `RelatedManager.get_queryset()` for a better understanding of how this comes into play.","provenance":"extracted_rationale","evidence_refs":[{"id":"ev_8aaef556652e1e34f5dc","repository":"default","kind":"file_content","path":"django/db/models/manager.py","line":158,"content_id":"4220a741d81fef4df260","range":[158,163],"provenance":"extracted_rationale","source":"live_code_rationale","source_kind":"code_comment","verification":"exact","verification_basis":"live"}]}],"_meta":{"contract_version":2,"index_age_days":0,"indexed_commit":"e78991410b78","live_head":"e78991410b78","index_behind":false,"index_scope":{"version":1,"projection":"compact","run_mode":"standard","content_provenance":"template","git_tier":"full","status":"upgrading","fingerprint":"99c42a358f89","full":"get_overview()","degraded_analyses":["Graph build can take several minutes on a first run. Safe to Ctrl-C — re-run 'repowise init --resume' to continue where it stopped."]},"embedder":"mock","embedder_degraded":false,"semantic_search":false,"response_budget":{"limit_chars":24000,"tier":"default","serialized_chars":3311},"completeness":{"capped":false},"replaced_tokens":3000,"tokens_saved":2188,"timing_ms":1983.1},"answer_basis":"rationale"}}