Skip to content

Commit 62eabc2

Browse files
migeed-zfacebook-github-bot
authored andcommitted
Add cross module reverse relation test (facebook#2090)
Summary: We are documenting this for coverage, but this will not be covered by the initial implementation. I do believe that this is an important case to consider though. I would expect a lot of the reverse relations would be spread across multiple modules. It's good that we can support them per module, but a complete implementation would support cross module as well. Reviewed By: stroxler Differential Revision: D90518264
1 parent 4a64a89 commit 62eabc2

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

pyrefly/lib/test/django/reverse_relations.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,25 @@
66
*/
77

88
use crate::django_testcase;
9+
use crate::test::django::util::django_env;
10+
use crate::test::util::TestEnv;
11+
use crate::testcase;
12+
13+
// Cross-module reverse relations: when the FK target is in a different module,
14+
// reverse relations cannot be synthesized yet because our current analysis only scans the current module.
15+
fn django_env_with_separate_models() -> TestEnv {
16+
let mut env = django_env();
17+
env.add(
18+
"author",
19+
r#"
20+
from django.db import models
21+
22+
class Author(models.Model):
23+
name = models.CharField(max_length=100)
24+
"#,
25+
);
26+
env
27+
}
928

1029
django_testcase!(
1130
bug = "Reverse relations not yet implemented",
@@ -77,3 +96,20 @@ person = Person()
7796
person.person_set # E: `Person` has no attribute `person_set`
7897
"#,
7998
);
99+
100+
testcase!(
101+
bug = "Cross-module reverse relations not supported",
102+
test_foreign_key_reverse_cross_module,
103+
django_env_with_separate_models(),
104+
r#"
105+
from django.db import models
106+
from .author import Author
107+
108+
class Book(models.Model):
109+
author = models.ForeignKey(Author, on_delete=models.CASCADE)
110+
111+
# Author is defined in a different module, so reverse relation won't be synthesized
112+
author = Author()
113+
author.book_set # E: `Author` has no attribute `book_set`
114+
"#,
115+
);

0 commit comments

Comments
 (0)