Skip to content

Commit ae50612

Browse files
migeed-zmeta-codesync[bot]
authored andcommitted
Extend class binding to store pk info
Summary: We collect the pk info in the binding layer. We want to propagate it to the class metadata layer so we expend the binding to handle that Reviewed By: rchen152 Differential Revision: D85478307 fbshipit-source-id: 33634325bef53d30f5b808d1f18a872dd3f82c76
1 parent 0d6b1d7 commit ae50612

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

pyrefly/lib/alt/solve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ impl<'a, Ans: LookupAnswer> AnswersSolver<'a, Ans> {
284284
decorators,
285285
is_new_type,
286286
pydantic_config_dict,
287+
django_primary_key_field: _,
287288
} = binding;
288289
let metadata = match &self.get_idx(*k).0 {
289290
None => ClassMetadata::recursive(),

pyrefly/lib/binding/binding.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ assert_words!(BindingAnnotation, 15);
102102
assert_words!(BindingClass, 23);
103103
assert_words!(BindingTParams, 10);
104104
assert_words!(BindingClassBaseType, 3);
105-
assert_words!(BindingClassMetadata, 8);
105+
assert_words!(BindingClassMetadata, 11);
106106
assert_bytes!(BindingClassMro, 4);
107107
assert_bytes!(BindingAbstractClassCheck, 4);
108108
assert_words!(BindingClassField, 21);
@@ -2035,6 +2035,9 @@ pub struct BindingClassMetadata {
20352035
/// Is this a new type? True only for synthesized classes created from a `NewType` call.
20362036
pub is_new_type: bool,
20372037
pub pydantic_config_dict: PydanticConfigDict,
2038+
/// The name of the field that has primary_key=True, if any (for Django models).
2039+
/// Note that we calculate this field for all classes, but it is ignored unless the class is a django model.
2040+
pub django_primary_key_field: Option<Name>,
20382041
}
20392042

20402043
impl DisplayWith<Bindings> for BindingClassMetadata {

pyrefly/lib/binding/class.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ impl<'a> BindingsBuilder<'a> {
345345
decorators: decorators_with_ranges.clone().into_boxed_slice(),
346346
is_new_type: false,
347347
pydantic_config_dict,
348+
django_primary_key_field: None,
348349
},
349350
);
350351
self.insert_binding_idx(
@@ -487,6 +488,7 @@ impl<'a> BindingsBuilder<'a> {
487488
decorators: Box::new([]),
488489
is_new_type,
489490
pydantic_config_dict: PydanticConfigDict::default(),
491+
django_primary_key_field: None,
490492
},
491493
);
492494
self.insert_binding_idx(

pyrefly/lib/report/binding_memory.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ mod tests {
165165
decorators: Default::default(),
166166
is_new_type: false,
167167
pydantic_config_dict: PydanticConfigDict::default(),
168+
django_primary_key_field: None,
168169
};
169170
assert_eq!(
170171
ReportKey::new(module, &v),

0 commit comments

Comments
 (0)