Skip to content

Conversation

@techouse
Copy link
Owner

@techouse techouse commented May 24, 2025

This pull request introduces changes to the query string decoding logic in qs_codec to improve handling of lists, particularly sparse and nested lists, and updates the corresponding unit tests to reflect the new behavior. The most significant changes include adding a safeguard for list limits, modifying the merging behavior for undefined values, and enhancing test cases for better coverage of edge cases.

Changes to decoding logic:

  • Safeguard for list limits: Added a condition in decode to disable list parsing when the number of elements exceeds the list_limit specified in DecodeOptions (src/qs_codec/decode.py).
  • Merging behavior update: Updated the merge function to consider the parse_lists option when handling undefined values, ensuring consistent behavior based on configuration (src/qs_codec/utils/utils.py).

Updates to test cases:

  • Revised test expectations: Adjusted test cases to reflect the new behavior of compacting sparse lists and handling list limits, including changes to test_parses_an_explicit_list, test_parses_a_nested_list, and test_compacts_sparse_lists (tests/unit/decode_test.py). [1] [2] [3]
  • Example test update: Updated the example test to reflect the new behavior of compacting sparse lists (tests/unit/example_test.py).

Fixes #18

Summary by CodeRabbit

  • Bug Fixes

    • Improved decoding of query strings to handle list parsing more consistently, especially for sparse or indexed lists.
    • Adjusted behavior so that lists with missing or non-sequential indices are now compacted into standard lists rather than dictionaries with string keys, depending on decoding options.
  • Tests

    • Updated and added test cases to reflect the new list compaction behavior and ensure reliable decoding results for various query string formats.

@techouse techouse self-assigned this May 24, 2025
@techouse techouse added the bug Something isn't working label May 24, 2025
@coderabbitai
Copy link

coderabbitai bot commented May 24, 2025

"""

Walkthrough

The changes update the logic for decoding query strings with indexed arrays, ensuring that when parse_lists is enabled, sparse arrays are compacted into lists rather than dictionaries. The decoding and utility modules are modified, and corresponding unit tests are updated to reflect and verify the new behavior.

Changes

File(s) Change Summary
src/qs_codec/decode.py Adds logic to disable parse_lists if the number of keys exceeds list_limit before final decoding.
src/qs_codec/utils/utils.py Alters merging logic to compact indexed arrays into lists only if parse_lists is enabled.
tests/unit/decode_test.py, example_test.py Updates test cases and expectations for decoding indexed arrays and list compaction behavior.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Decoder
    participant Utils

    Client->>Decoder: decode(query, options)
    Decoder->>Decoder: parse query into temp_obj
    alt parse_lists enabled and key count > list_limit
        Decoder->>Decoder: set options.parse_lists = False
    end
    Decoder->>Utils: merge/compact temp_obj based on options
    Utils-->>Decoder: return merged/compacted object
    Decoder-->>Client: return decoded object
Loading

Assessment against linked issues

Objective Addressed Explanation
Parse indexed arrays as lists when parse_lists is enabled (#18)

Possibly related PRs

Poem

🐇
In code we hop, from dict to list,
Compacting arrays so nothing is missed.
Indices vanish, the order is true,
Now "a[1]=b&a[15]=c" gives a list anew.
With tests all green, we leap with delight—
Decoding arrays now feels just right!

"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5185095 and f2edaed.

📒 Files selected for processing (1)
  • src/qs_codec/decode.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/qs_codec/decode.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f81192c and 5185095.

📒 Files selected for processing (4)
  • src/qs_codec/decode.py (1 hunks)
  • src/qs_codec/utils/utils.py (1 hunks)
  • tests/unit/decode_test.py (3 hunks)
  • tests/unit/example_test.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/qs_codec/utils/utils.py (1)
src/qs_codec/models/undefined.py (1)
  • Undefined (6-15)
tests/unit/decode_test.py (1)
src/qs_codec/models/decode_options.py (1)
  • DecodeOptions (12-97)
🪛 GitHub Actions: Test
src/qs_codec/decode.py

[error] 38-38: mypy error: Argument 1 to "len" has incompatible type "Optional[dict[str, Any]]"; expected "Sized" [arg-type]

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (5)
tests/unit/example_test.py (1)

123-123: LGTM: Test correctly reflects new sparse list compaction behavior.

The test expectation has been properly updated to reflect that sparse indexed lists ("a[1]=b&a[15]=c") are now compacted to ["b", "c"] instead of preserving original indices as dictionary keys. This aligns with the improved list parsing behavior described in the PR objectives.

src/qs_codec/utils/utils.py (1)

41-41: LGTM: Correctly respects the parse_lists option in merge logic.

The additional condition not options.parse_lists ensures that the transformation to a dictionary with string keys only occurs when list parsing is disabled. This maintains consistency with the parse_lists configuration throughout the decoding process and aligns with the PR's objective to improve list parsing behavior.

tests/unit/decode_test.py (3)

255-255: LGTM: Test expectation correctly updated for sparse list compaction.

The expected output has been properly updated from a dictionary with string keys to a compacted list ["b", "c"], which correctly reflects the new behavior where sparse indexed lists are compacted when parse_lists is enabled.


293-316: Excellent test coverage for parse_lists option behavior.

These new test cases provide comprehensive coverage for the parse_lists option, verifying that:

  • When parse_lists=True: sparse lists are compacted into arrays
  • When parse_lists=False: indices are preserved as dictionary keys

This ensures the option works correctly for various scenarios including missing indices and different starting positions.


538-549: LGTM: Simplified and improved sparse list compaction tests.

The test parameters and expectations have been correctly updated to reflect the new sparse list compaction behavior. The simplification (removing unnecessary assertions) makes the tests cleaner while still verifying the core functionality that sparse lists are properly compacted into sequential arrays.

@codacy-production
Copy link

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.12% (target: -1.00%) 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (f81192c) 792 780 98.48%
Head commit (f2edaed) 794 (+2) 781 (+1) 98.36% (-0.12%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#19) 3 3 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@codecov
Copy link

codecov bot commented May 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.36%. Comparing base (f81192c) to head (f2edaed).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #19      +/-   ##
==========================================
- Coverage   98.48%   98.36%   -0.13%     
==========================================
  Files          16       16              
  Lines         792      794       +2     
==========================================
+ Hits          780      781       +1     
- Misses         12       13       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@techouse techouse merged commit 1a10cea into main May 24, 2025
16 of 17 checks passed
@techouse techouse deleted the fix/issue-18 branch May 24, 2025 08:24
techouse added a commit that referenced this pull request May 24, 2025
## 1.1.3

* [FIX] list with indexes always get parsed into dict ([#19](#19))
@coderabbitai coderabbitai bot mentioned this pull request Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array with indexes always get parsed into dict

2 participants