PerlDancer / PerlDancer/Dancer2

params('query') returns undef until params() has been called

Open Beginner friendly
#1,811 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
Perl
Stars
604
Forks
288
Avg merge
1d 5h
Merged PRs (30d)
5

Description

Status: confirmed against main @ 21bc21d9

lib/Dancer2/Core/Request.pm:130 and 346-349. _query_params is a bare hash read with no lazy builder, unlike its two siblings which both self-initialise:

sub _body_params  { $_[0]->{'_body_params'}  ||= $_[0]->body_parameters->as_hashref_mixed }
sub _query_params { $_[0]->{'_query_params'} }                      # <-- no ||=
sub _route_params { $_[0]->{'_route_params'} ||= {} }

Reproduction

A) params("query") BEFORE any params() call: UNDEF
B) params("query") AFTER  params() call    : hashref

Impact

It usually works inside a route handler, because dispatch calls _set_route_params_build_params_parse_get_params on the way in. It breaks in early hooks that run before route matching, and in any code path reaching params('query') first. In list context it is worse — %{ undef }.

Suggested fix

sub _query_params { $_[0]->{'_query_params'} ||= $_[0]->_parse_get_params }

Note _parse_get_params already returns early with $self->_query_params when the value is set (line 539). That guard still terminates once the accessor is lazy, because _set_query_params writes the hash element directly rather than going through the accessor — but it is subtle enough to deserve a test.

Suggested test

params('query') returns a hashref on a fresh request with no prior params() call.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/Dancer2/Core/Request.pm at _query_params around line 130 and the related logic around lines 346-349 and 539. Verify params('query') on a fresh request before any params() call, then add coverage showing it returns a hashref and that the existing lazy-parse guard still behaves correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.