Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changes/unreleased/Fixes-20250902-153838.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Fixes
body: Implement support for the second optional argument to dict.pop() in jinja
time: 2025-09-02T15:38:38.362214+02:00
custom:
author: fornwall
issue: "659"
project: dbt-fusion
7 changes: 4 additions & 3 deletions crates/dbt-jinja/minijinja/src/value/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1550,16 +1550,17 @@ pub mod mutable_map {
fn pop_impl(map: &Arc<MutableMap>, args: &[Value]) -> Result<Value, Error> {
match args {
[key] => Ok(map.remove(key).unwrap_or_default()),
_ if args.len() > 1 => Err(Error::new(
[key, default] => Ok(map.remove(key).unwrap_or_else(|| default.clone())),
_ if args.len() > 2 => Err(Error::new(
ErrorKind::TooManyArguments,
format!(
"remove() takes exactly one argument, but {} were given",
"pop() takes one or two arguments, but {} were given",
args.len()
),
)),
_ => Err(Error::new(
ErrorKind::MissingArgument,
"remove() takes exactly one argument, but none were given",
"pop() takes one or two arguments, but none were given",
)),
}
}
Expand Down
4 changes: 3 additions & 1 deletion crates/dbt-jinja/minijinja/tests/inputs/dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
{{ dict(x=1, y=2) }}
{{ dict(d, c=3)}}
{% for _ in [1] %}{{ dict(loop, extra=2)|dictsort }}{% endfor %}
{{ dict([('a', 1), ('b', 2), ('c', 3)]) }}
{{ dict([('a', 1), ('b', 2), ('c', 3)]) }}
{{ {'a':'b'}.pop('a') }}
{{ {}.pop('a','b') }}
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ input_file: fs/sa/crates/dbt-jinja/minijinja/tests/inputs/dict.txt
{'a': 1, 'b': 2, 'c': 3}
(('depth', 1), ('depth0', 0), ('extra', 2), ('first', true), ('index', 1), ('index0', 0), ('last', true), ('length', 1), ('nextitem', undefined), ('previtem', undefined), ('revindex', 1), ('revindex0', 0))
{'a': 1, 'b': 2, 'c': 3}
b
b