Skip to content

Commit f3719f4

Browse files
committed
[FIX] server: base_attr for decorators
When evaluatiing decorators api.depends, the field we are searching has no "base_attr" in its context has we are searching it from a string. So decorator used in relational fields are not working properly. This fix add base_attr in local context to help evaluation or relation fields.
1 parent c6e16e7 commit f3719f4

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

server/src/core/symbols/symbol.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2044,7 +2044,14 @@ impl Symbol {
20442044
let mut res = VecDeque::new();
20452045
let symbol = &*symbol_rc.borrow();
20462046
if !stop_on_type {
2047-
if let Some(base_attr) = symbol_context.get(&S!("base_attr")) {
2047+
let mut base_attr = symbol_context.get(&S!("base_attr"));
2048+
if base_attr.is_none() {
2049+
//search in context (used in decorators to indicate on which base the field is searched)
2050+
if let Some(context) = context.as_ref() {
2051+
base_attr = context.get(&S!("base_attr"));
2052+
}
2053+
}
2054+
if let Some(base_attr) = base_attr {
20482055
let base_attr = base_attr.as_symbol().upgrade();
20492056
if let Some(base_attr) = base_attr {
20502057
let attribute_type_sym = symbol;

server/src/core/symbols/variable_symbol.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ruff_text_size::TextRange;
22

3-
use crate::{constants::{OYarn, SymType}, core::evaluation::Evaluation, oyarn, threads::SessionInfo};
4-
use std::{cell::RefCell, rc::{Rc, Weak}};
3+
use crate::{constants::{OYarn, SymType}, core::evaluation::{ContextValue, Evaluation}, oyarn, threads::SessionInfo, Sy};
4+
use std::{cell::RefCell, collections::HashMap, rc::{Rc, Weak}, u32};
55

66
use super::symbol::Symbol;
77

@@ -62,7 +62,14 @@ impl VariableSymbol {
6262
pub fn get_relational_model(&self, session: &mut SessionInfo, from_module: Option<Rc<RefCell<Symbol>>>) -> Vec<Rc<RefCell<Symbol>>> {
6363
for eval in self.evaluations.iter() {
6464
let symbol = eval.symbol.get_symbol(session, &mut None, &mut vec![], None);
65-
let eval_weaks = Symbol::follow_ref(&symbol, session, &mut None, false, false, None, &mut vec![]);
65+
let mut context = None;
66+
if let Some(parent) = self.parent.as_ref() {
67+
// To be able to follow related fields, we need to have the base_attr set in order to find the __get__ hook in next_refs
68+
// we update the context here for the case where we are coming from a decorator for example.
69+
context = Some(HashMap::new());
70+
context.as_mut().unwrap().insert(Sy!("base_attr"), ContextValue::SYMBOL(parent.clone()));
71+
}
72+
let eval_weaks = Symbol::follow_ref(&symbol, session, &mut context, false, false, None, &mut vec![]);
6673
for eval_weak in eval_weaks.iter() {
6774
if let Some(symbol) = eval_weak.upgrade_weak() {
6875
if ["Many2one", "One2many", "Many2many"].contains(&symbol.borrow().name().as_str()) {

0 commit comments

Comments
 (0)