Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qe: fix mongo logging for updateMany #3321

Merged
merged 4 commits into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ mod max_integer {
const I16_OVERFLOW_MAX: i64 = (i16::MAX as i64) + 1;
const I16_OVERFLOW_MIN: i64 = (i16::MIN as i64) - 1;

const I24_OVERFLOW_MAX: i64 = (8388607 as i64) + 1;
const I24_OVERFLOW_MIN: i64 = (-8388608 as i64) - 1;
const I24_OVERFLOW_MAX: i64 = 8388607 + 1;
const I24_OVERFLOW_MIN: i64 = -8388608 - 1;

const I32_OVERFLOW_MAX: i64 = (i32::MAX as i64) + 1;
const I32_OVERFLOW_MIN: i64 = (i32::MIN as i64) - 1;

const U8_OVERFLOW_MAX: i64 = (u8::MAX as i64) + 1;
const U16_OVERFLOW_MAX: i64 = (u16::MAX as i64) + 1;
const U24_OVERFLOW_MAX: i64 = (16777215 as i64) + 1;
const U24_OVERFLOW_MAX: i64 = 16777215 + 1;
const U32_OVERFLOW_MAX: i64 = (u32::MAX as i64) + 1;
const OVERFLOW_MIN: i8 = -1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod prisma_14696;
mod prisma_14703;
mod prisma_15204;
mod prisma_15264;
mod prisma_15467;
mod prisma_15581;
mod prisma_15607;
mod prisma_5952;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use query_engine_tests::*;

#[test_suite(schema(schema), only(MongoDb))]
mod mongodb {
use indoc::indoc;

fn schema() -> String {
let schema = indoc! {
r#"
model Standing {
id String @id @default(auto()) @map("_id") @test.ObjectId
leagueId Int
teamId Int
awayLosses Int
}
"#
};
schema.to_owned()
}

#[connector_test]
async fn update_many_log_output(mut runner: Runner) -> TestResult<()> {
let insert_one_standing = r#"
mutation {
createOneStanding(data:{leagueId: 0, teamId: 0, awayLosses: 0}) {
id
}
}"#;

let res = run_query_json!(&runner, insert_one_standing);
let object_id = &res["data"]["createOneStanding"]["id"];

dbg!(object_id);
let _ = runner.get_logs().await;
run_query!(
&runner,
format!(
r#"
mutation {{
updateManyStanding(data:{{awayLosses:{{set: 0}}, teamId:{{set: 972030012}}, leagueId:{{set: 2363725}}}}, where:{{id: {{equals: {} }}}}) {{
count
}}
}}
"#,
object_id
)
);
let logs = runner.get_logs().await;
let last_log_line = logs.last().unwrap();
let expected = format!(
r##"db.Standing.updateMany({{
_id: {{
$in: [
ObjectId({}),
],
}},
}}, [
{{
$set: {{
leagueId: {{
$literal: 2363725,
}},
}},
}},
{{
$set: {{
teamId: {{
$literal: 972030012,
}},
}},
}},
{{
$set: {{
awayLosses: {{
$literal: 0,
}},
}},
}}])"##,
object_id
);

assert!(
last_log_line.contains(expected.as_str()),
"{} should have contained {}",
last_log_line,
expected
);
Ok(())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fn create_env_filter(log_queries: bool, qe_log_level: &str) -> EnvFilter {
.add_directive(format!("query_core={}", &qe_log_level).parse().unwrap())
.add_directive(format!("query_connector={}", &qe_log_level).parse().unwrap())
.add_directive(format!("sql_query_connector={}", &qe_log_level).parse().unwrap())
.add_directive(format!("mongodb_query_connector={}", &qe_log_level).parse().unwrap());
.add_directive("mongodb_query_connector=debug".parse().unwrap());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch


if log_queries {
filter = filter.add_directive("quaint[{is_query}]=trace".parse().unwrap());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@ pub(crate) fn log_update_many_vec(coll: &str, filter: &Document, docs: &[Documen
write!(&mut buffer, ", [").unwrap();
}

for doc in docs {
fmt_doc(&mut buffer, doc, 1).unwrap();
if let Some((last, docs)) = docs.split_last() {
for doc in docs {
fmt_doc(&mut buffer, doc, 1).unwrap();
writeln!(&mut buffer, ",").unwrap();
}
fmt_doc(&mut buffer, last, 1).unwrap();
}

write!(&mut buffer, "])").unwrap();
Expand Down