Skip to content

Commit d372b42

Browse files
mmahroussfda-odoo
authored andcommitted
[FIX] server: quit function validation when ast changes
And check the processed hash on the parent file, also remove processed_text_hash from Function symbol as it is not needed anymore
1 parent 09d1ae3 commit d372b42

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

server/src/core/python_arch_builder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ impl PythonArchBuilder {
9696
&AstUtils::find_stmt_from_ast(file_info.ast.as_ref().unwrap(), self.sym_stack[0].borrow().ast_indexes().unwrap()).as_function_def_stmt().unwrap().body
9797
}
9898
};
99-
symbol.borrow_mut().set_processed_text_hash(file_info.text_hash);
99+
if self.file_mode {
100+
symbol.borrow_mut().set_processed_text_hash(file_info.text_hash);
101+
}
100102
self.visit_node(session, &ast);
101103
self._resolve_all_symbols(session);
102104
if self.file_mode {
@@ -431,8 +433,6 @@ impl PythonArchBuilder {
431433
self.sym_stack.push(sym.clone());
432434
self.visit_node(session, &func_def.body)?;
433435
self.sym_stack.pop();
434-
let file_info_rc = session.sync_odoo.get_file_mgr().borrow().get_file_info(&self.file.borrow().get_symbol_first_path()).unwrap();
435-
sym.borrow_mut().set_processed_text_hash(file_info_rc.borrow().text_hash);
436436
sym.borrow_mut().as_func_mut().arch_status = BuildStatus::DONE;
437437
}
438438
Ok(())

server/src/core/python_validator.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,14 @@ impl PythonValidator {
9292
}
9393
self.file_mode = false;
9494
let func = &self.sym_stack[0];
95-
if func.borrow().as_func().arch_status == BuildStatus::PENDING || file_info_rc.borrow().text_hash != func.borrow().get_processed_text_hash(){ //TODO other checks to do? maybe odoo step, or?????????
95+
let Some(parent_file) = func.borrow().get_file().and_then(|parent_weak| parent_weak.upgrade()) else {
96+
panic!("Parent file not found on validating function")
97+
};
98+
if file_info_rc.borrow().text_hash != parent_file.borrow().get_processed_text_hash(){
99+
self.sym_stack[0].borrow_mut().set_build_status(BuildSteps::VALIDATION, BuildStatus::INVALID);
100+
return;
101+
}
102+
if func.borrow().as_func().arch_status == BuildStatus::PENDING { //TODO other checks to do? maybe odoo step, or?????????
96103
self.sym_stack[0].borrow_mut().set_build_status(BuildSteps::ARCH, BuildStatus::PENDING);
97104
self.sym_stack[0].borrow_mut().set_build_status(BuildSteps::ARCH_EVAL, BuildStatus::PENDING);
98105
self.sym_stack[0].borrow_mut().set_build_status(BuildSteps::VALIDATION, BuildStatus::PENDING);

server/src/core/symbols/function_symbol.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub struct FunctionSymbol {
4848
pub args: Vec<Argument>,
4949
pub is_overloaded: bool, //used for @overload decorator. Only indicates if the decorator is present. Use is_overloaded() to know if this function is overloaded
5050
pub is_class_method: bool, //used for @classmethod decorator
51-
pub processed_text_hash: u64,
5251

5352
//Trait SymbolMgr
5453
//--- Body content
@@ -86,7 +85,6 @@ impl FunctionSymbol {
8685
args: vec![],
8786
is_overloaded: false,
8887
is_class_method: false,
89-
processed_text_hash: 0,
9088
};
9189
res._init_symbol_mgr();
9290
res

server/src/core/symbols/symbol.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,9 +1385,9 @@ impl Symbol {
13851385
pub fn set_processed_text_hash(&mut self, hash: u64){
13861386
match self {
13871387
Symbol::File(f) => f.processed_text_hash = hash,
1388-
Symbol::Function(f) => f.processed_text_hash = hash,
13891388
Symbol::Package(PackageSymbol::Module(m)) => m.processed_text_hash = hash,
13901389
Symbol::Package(PackageSymbol::PythonPackage(p)) => p.processed_text_hash = hash,
1390+
Symbol::Function(_) => panic!("set_processed_text_hash called on Function"),
13911391
Symbol::Root(_) => panic!("set_processed_text_hash called on Root"),
13921392
Symbol::Namespace(_) => panic!("set_processed_text_hash called on Namespace"),
13931393
Symbol::Compiled(_) => panic!("set_processed_text_hash called on Compiled"),
@@ -1399,9 +1399,9 @@ impl Symbol {
13991399
pub fn get_processed_text_hash(&self) -> u64{
14001400
match self {
14011401
Symbol::File(f) => f.processed_text_hash,
1402-
Symbol::Function(f) => f.processed_text_hash,
14031402
Symbol::Package(PackageSymbol::Module(m)) => m.processed_text_hash,
14041403
Symbol::Package(PackageSymbol::PythonPackage(p)) => p.processed_text_hash,
1404+
Symbol::Function(_) => panic!("get_processed_text_hash called on Function"),
14051405
Symbol::Root(_) => panic!("get_processed_text_hash called on Root"),
14061406
Symbol::Namespace(_) => panic!("get_processed_text_hash called on Namespace"),
14071407
Symbol::Compiled(_) => panic!("get_processed_text_hash called on Compiled"),

0 commit comments

Comments
 (0)