Skip to content

Commit 7ce1c5e

Browse files
committed
feat: Handle queryset keyworkd in Prefetch object
1 parent 71a6b22 commit 7ce1c5e

File tree

6 files changed

+263
-34
lines changed

6 files changed

+263
-34
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ Runtime tools (django-silk, nplusone) are focuesd in runtime optimiezation. `dja
4343
* ManyToMany
4444
* Inheritance
4545
* Reverse relations (with `related_name` explicit or not)
46+
* Complex chained relations like `model__relation__child_relation__depth`
47+
* Prefetch usage: `Prefetch("relation", queryset=Relation.objects.select_related("child")`
4648

4749
## Installation
4850

@@ -178,13 +180,11 @@ for user in users:
178180

179181
* Interprocedural analysis requires type hints on QuerySet parameters
180182
* Limited understanding of:
181-
* `Prefetch` objects with basic access support (e.g. `Prefetch("related_model")`)
182183
* `annotate`, `aggregate`
183184
* complex custom managers
184185

185186
## Roadmap
186187

187-
* Complete Prefetch object support
188188
* Custom queryset method summaries
189189
* Templates integration
190190

crates/django-check/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "django-check"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
rust-version = { workspace = true }
55
license = { workspace = true }
66
authors = { workspace = true }

crates/django-check_semantic/src/ir/binding.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,23 @@ impl QuerySetState {
3434
}
3535
}
3636

37+
/// Information about a Prefetch object (e.g., `Prefetch("orders", queryset=...)`)
38+
#[derive(Debug, Clone, Eq, PartialEq)]
39+
pub struct PrefetchInfo {
40+
/// The lookup string (e.g., "orders" or "orders__items")
41+
pub lookup: String,
42+
/// The queryset's state if a custom queryset was provided
43+
pub queryset_state: Option<QuerySetState>,
44+
}
45+
3746
#[derive(Debug, Clone, Eq, PartialEq)]
3847
pub enum DjangoSymbol {
3948
/// A `QuerySet` instance (e.g., `User.objects.all()`)
4049
QuerySet(QuerySetState),
4150
/// A Model instance (e.g., `user` inside a loop)
4251
ModelInstance(QuerySetState),
52+
/// A Prefetch object (e.g., `Prefetch("orders", queryset=...)`)
53+
Prefetch(PrefetchInfo),
4354
}
4455

4556
#[derive(Debug, Clone, Eq, PartialEq)]

crates/django-check_semantic/src/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl Parser {
113113
.parse_module(source)
114114
.map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidInput, "parsing module"))?;
115115

116-
let mut pass = ModelGraphPass::new(&filename, &source);
116+
let mut pass = ModelGraphPass::new(filename, source);
117117
Ok(pass.run(parsed.syntax()))
118118
}
119119

0 commit comments

Comments
 (0)