Skip to content

Commit b21f815

Browse files
mmahroussfda-odoo
authored andcommitted
[FIX] server: correct default representation for user
1 parent 03bbbfb commit b21f815

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

server/src/constants.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,6 @@ pub const BUILT_IN_LIBS: &[&str] = &["string", "re", "difflib", "textwrap", "un
118118
"tabnanny", "pyclbr", "py_compile", "compileall", "dis", "pickletools", "msvcrt", "winreg", "winsound", "posix",
119119
"pwd", "grp", "termios", "tty", "pty", "fcntl", "resource", "syslog", "aifc", "asynchat", "asyncore", "audioop",
120120
"cgi", "cgitb", "chunk", "crypt", "imghdr", "imp", "mailcap", "msilib", "nis", "nntplib", "optparse", "ossaudiodev",
121-
"pipes", "smtpd", "sndhdr", "spwd", "sunau", "telnetlib", "uu", "xdrlib", "struct", "codecs"];
121+
"pipes", "smtpd", "sndhdr", "spwd", "sunau", "telnetlib", "uu", "xdrlib", "struct", "codecs"];
122+
123+
pub const DEFAULT_PYTHON: &str = "python3";

server/src/core/config.rs

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use ruff_python_ast::{Expr, Mod};
1010
use ruff_python_parser::{Mode, ParseOptions};
1111
use serde::{Deserialize, Deserializer, Serialize, Serializer};
1212

13+
use crate::constants::DEFAULT_PYTHON;
1314
use crate::utils::{fill_validate_path, has_template, is_addon_path, is_odoo_path, is_python_path, PathSanitizer};
1415
use crate::S;
1516

@@ -344,6 +345,50 @@ where
344345
}
345346
}
346347

348+
pub fn serialize_python_path<T, S>(opt: &Option<T>, serializer: S) -> Result<S::Ok, S::Error>
349+
where
350+
T: Serialize + Default,
351+
S: Serializer,
352+
{
353+
match opt {
354+
Some(val) => val.serialize(serializer),
355+
None => (Sourced { value: S!(DEFAULT_PYTHON), ..Default::default() }).serialize(serializer),
356+
}
357+
}
358+
359+
pub fn serialize_file_cache<T, S>(opt: &Option<T>, serializer: S) -> Result<S::Ok, S::Error>
360+
where
361+
T: Serialize + Default,
362+
S: Serializer,
363+
{
364+
match opt {
365+
Some(val) => val.serialize(serializer),
366+
None => (Sourced { value: true, ..Default::default() }).serialize(serializer),
367+
}
368+
}
369+
370+
pub fn serialize_ac_filter_model_names<T, S>(opt: &Option<T>, serializer: S) -> Result<S::Ok, S::Error>
371+
where
372+
T: Serialize + Default,
373+
S: Serializer,
374+
{
375+
match opt {
376+
Some(val) => val.serialize(serializer),
377+
None => (Sourced { value: true, ..Default::default() }).serialize(serializer),
378+
}
379+
}
380+
381+
pub fn serialize_auto_refresh_delay<T, S>(opt: &Option<T>, serializer: S) -> Result<S::Ok, S::Error>
382+
where
383+
T: Serialize + Default,
384+
S: Serializer,
385+
{
386+
match opt {
387+
Some(val) => val.serialize(serializer),
388+
None => (Sourced { value: 1000, ..Default::default() }).serialize(serializer),
389+
}
390+
}
391+
347392
fn parse_manifest_version(contents: String) -> Option<String> {
348393
let parsed = ruff_python_parser::parse_unchecked(contents.as_str(), ParseOptions::from(Mode::Module));
349394
if !parsed.errors().is_empty() {
@@ -429,7 +474,7 @@ pub struct ConfigEntryRaw {
429474
#[serde(default, serialize_with = "serialize_option_as_default")]
430475
addons_paths: Option<Vec<Sourced<String>>>,
431476

432-
#[serde(default, serialize_with = "serialize_option_as_default")]
477+
#[serde(default, serialize_with = "serialize_python_path")]
433478
python_path: Option<Sourced<String>>,
434479

435480
#[serde(default, serialize_with = "serialize_option_as_default")]
@@ -441,16 +486,16 @@ pub struct ConfigEntryRaw {
441486
#[serde(default, serialize_with = "serialize_option_as_default")]
442487
refresh_mode: Option<Sourced<RefreshMode>>,
443488

444-
#[serde(default, serialize_with = "serialize_option_as_default")]
489+
#[serde(default, serialize_with = "serialize_file_cache")]
445490
file_cache: Option<Sourced<bool>>,
446491

447492
#[serde(default, serialize_with = "serialize_option_as_default")]
448493
diag_missing_imports: Option<Sourced<DiagMissingImportsMode>>,
449494

450-
#[serde(default, serialize_with = "serialize_option_as_default")]
495+
#[serde(default, serialize_with = "serialize_ac_filter_model_names")]
451496
ac_filter_model_names: Option<Sourced<bool>>,
452497

453-
#[serde(default, serialize_with = "serialize_option_as_default")]
498+
#[serde(default, serialize_with = "serialize_auto_refresh_delay")]
454499
auto_refresh_delay: Option<Sourced<u64>>,
455500

456501
#[serde(default, serialize_with = "serialize_option_as_default")]
@@ -529,7 +574,7 @@ impl Default for ConfigEntry {
529574
Self {
530575
odoo_path: None,
531576
addons_paths: HashSet::new(),
532-
python_path: S!("python3"),
577+
python_path: S!(DEFAULT_PYTHON),
533578
additional_stubs: HashSet::new(),
534579
refresh_mode: RefreshMode::default(),
535580
file_cache: true,
@@ -1001,7 +1046,7 @@ fn merge_all_workspaces(
10011046
ConfigEntry {
10021047
odoo_path: raw_entry.odoo_path.map(|op| op.value),
10031048
addons_paths: raw_entry.addons_paths.into_iter().flatten().map(|op| op.value).collect(),
1004-
python_path: raw_entry.python_path.map(|op| op.value).unwrap_or(S!("python3")),
1049+
python_path: raw_entry.python_path.map(|op| op.value).unwrap_or(S!(DEFAULT_PYTHON)),
10051050
additional_stubs: raw_entry.additional_stubs.into_iter().flatten().map(|op| op.value).collect(),
10061051
refresh_mode: raw_entry.refresh_mode.map(|op| op.value).unwrap_or_default(),
10071052
file_cache: raw_entry.file_cache.map(|op| op.value).unwrap_or(true),

0 commit comments

Comments
 (0)