Skip to content

Feat/ser/wr only#62

Merged
j03-dev merged 4 commits intomainfrom
feat/ser/wr_only
Jul 9, 2025
Merged

Feat/ser/wr only#62
j03-dev merged 4 commits intomainfrom
feat/ser/wr_only

Conversation

@j03-dev
Copy link
Copy Markdown
Owner

@j03-dev j03-dev commented Jul 9, 2025

Summary by CodeRabbit

  • New Features
    • Added support for read_only and write_only flags to serializer fields, allowing fields to be excluded from deserialization or serialization as appropriate.
  • Documentation
    • Updated documentation to describe the behavior of read_only and write_only flags in serializers.
  • Tests
    • Introduced tests to verify correct handling of read_only and write_only fields during serialization and deserialization.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Jul 9, 2025

Walkthrough

Support for read_only and write_only flags was added to serializer fields and the main serializer logic. Fields can now be marked to be excluded from deserialization or serialization, respectively. Tests were introduced to verify that these flags work as intended for both input validation and output representation.

Changes

File(s) Change Summary
src/serializer/fields.rs Added read_only and write_only fields and constructor args to Field struct and macro; updated docs.
src/serializer/mod.rs Updated Serializer to handle new flags: exclude read_only fields from input, write_only from output; added docs.
tests/test.py Added test for read_only/write_only serializer logic; introduced Base ORM class; minor formatting fix.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Serializer
    participant Field

    Client->>Serializer: validate(input_data)
    Serializer->>Field: check read_only flag
    alt Field is read_only
        Serializer-->>Serializer: Exclude field from validated data
    else Field is not read_only
        Serializer-->>Serializer: Include field in validated data
    end
    Serializer-->>Client: return validated data

    Client->>Serializer: to_representation(instance)
    Serializer->>Field: check write_only flag
    alt Field is write_only
        Serializer-->>Serializer: Exclude field from output
    else Field is not write_only
        Serializer-->>Serializer: Include field in output
    end
    Serializer-->>Client: return serialized output
Loading

Possibly related PRs

  • j03-dev/oxapy#60: Adds a length attribute to the Field struct and constructors, similar in approach to the addition of read_only and write_only flags.

Poem

A field may be read, or a field may be written,
With new flags, their secrets are now well-hidden.
Read-only for eyes, write-only for ears,
Serialization flows, as the intent now appears!
🐇✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Clippy (1.86.0)
Updating crates.io index

warning: failed to write cache, path: /usr/local/registry/index/index.crates.io-1949cf8c6b5b557f/.cache/ah/as/ahash, error: Permission denied (os error 13)
Downloading crates ...
Downloaded bit-vec v0.8.0
error: failed to create directory /usr/local/registry/cache/index.crates.io-1949cf8c6b5b557f

Caused by:
Permission denied (os error 13)


📜 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 e719774 and 2fc536e.

📒 Files selected for processing (1)
  • src/serializer/mod.rs (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/serializer/mod.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: musllinux (ubuntu-22.04, aarch64)
  • GitHub Check: linux (ubuntu-22.04, armv7)
  • GitHub Check: linux (ubuntu-22.04, ppc64le)
  • GitHub Check: musllinux (ubuntu-22.04, x86)
  • GitHub Check: macos (macos-14, aarch64)
  • GitHub Check: musllinux (ubuntu-22.04, armv7)
  • GitHub Check: musllinux (ubuntu-22.04, x86_64)
  • GitHub Check: linux (ubuntu-22.04, s390x)
  • GitHub Check: macos (macos-13, x86_64)
  • GitHub Check: windows (windows-latest, x86)
  • GitHub Check: linux (ubuntu-22.04, x86)
  • GitHub Check: linux (ubuntu-22.04, x86_64)
  • GitHub Check: linux (ubuntu-22.04, aarch64)
  • GitHub Check: windows (windows-latest, x64)
✨ 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.

@j03-dev j03-dev linked an issue Jul 9, 2025 that may be closed by this pull request
Copy link
Copy Markdown
Contributor

@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

🧹 Nitpick comments (2)
tests/test.py (1)

78-103: Comprehensive test for read_only and write_only functionality.

The test correctly verifies that:

  • read_only fields (id) are excluded from validated_data
  • write_only fields (password) are excluded from serialized output

Consider adding edge case tests:

  • A field with both read_only=True and write_only=True
  • Nested serializers with these flags
  • Many=True scenarios with these flags
src/serializer/mod.rs (1)

338-341: Remove redundant attribute check.

The condition slf.getattr(&col).is_ok() is redundant since the field was already successfully extracted on line 338.

Apply this diff to simplify the condition:

-            let field: Field = slf.getattr(&col)?.extract()?;
-            if slf.getattr(&col).is_ok() && !field.write_only.unwrap_or_default() {
+            if let Ok(field_attr) = slf.getattr(&col) {
+                let field: Field = field_attr.extract()?;
+                if !field.write_only.unwrap_or_default() {
                 dict.set_item(&col, instance.getattr(&col)?)?;
             }
+            }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bfe213a and e719774.

📒 Files selected for processing (3)
  • src/serializer/fields.rs (9 hunks)
  • src/serializer/mod.rs (7 hunks)
  • tests/test.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
tests/test.py (1)
src/serializer/mod.rs (13)
  • serializer (439-439)
  • serializer (440-440)
  • serializer (441-441)
  • serializer (442-442)
  • serializer (443-443)
  • serializer (444-444)
  • serializer (445-445)
  • serializer (446-446)
  • serializer (447-447)
  • serializer (448-448)
  • serializer (449-449)
  • is_valid (140-153)
  • data (211-233)
src/serializer/mod.rs (1)
src/serializer/fields.rs (1)
  • new (76-104)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: linux (ubuntu-22.04, s390x)
  • GitHub Check: linux (ubuntu-22.04, aarch64)
  • GitHub Check: linux (ubuntu-22.04, ppc64le)
  • GitHub Check: linux (ubuntu-22.04, x86_64)
  • GitHub Check: linux (ubuntu-22.04, armv7)
  • GitHub Check: linux (ubuntu-22.04, x86)
  • GitHub Check: windows (windows-latest, x86)
  • GitHub Check: macos (macos-13, x86_64)
  • GitHub Check: macos (macos-14, aarch64)
  • GitHub Check: windows (windows-latest, x64)
  • GitHub Check: musllinux (ubuntu-22.04, aarch64)
  • GitHub Check: musllinux (ubuntu-22.04, armv7)
  • GitHub Check: musllinux (ubuntu-22.04, x86_64)
  • GitHub Check: musllinux (ubuntu-22.04, x86)
🔇 Additional comments (5)
src/serializer/fields.rs (3)

28-31: LGTM!

The addition of read_only and write_only fields to the Field struct is implemented correctly with appropriate PyO3 getters.


53-54: Constructor updates are well implemented.

The documentation clearly explains the behavior of read_only and write_only fields, and the constructor properly initializes them.

Also applies to: 71-72, 87-88, 101-102


195-196: Macro updates are consistent and complete.

The define_fields! macro correctly propagates the read_only and write_only parameters to all field subclasses.

Also applies to: 208-209, 221-222, 237-238

tests/test.py (1)

2-2: SQLAlchemy setup looks good.

The imports and Base class are properly configured for the ORM model used in the test.

Also applies to: 6-8

src/serializer/mod.rs (1)

58-59: Constructor properly extended for read_only and write_only support.

The documentation and implementation correctly handle the new fields.

Also applies to: 78-80, 89-90, 104-105

Comment thread src/serializer/mod.rs Outdated
@j03-dev j03-dev merged commit 0df92b2 into main Jul 9, 2025
17 checks passed
@j03-dev j03-dev deleted the feat/ser/wr_only branch July 9, 2025 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Read & Write only Features for field in serializer

1 participant