Conversation
WalkthroughSupport for Changes
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
Possibly related PRs
Poem
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)warning: failed to write cache, path: /usr/local/registry/index/index.crates.io-1949cf8c6b5b557f/.cache/ah/as/ahash, error: Permission denied (os error 13) Caused by: 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
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_onlyfields (id) are excluded fromvalidated_datawrite_onlyfields (password) are excluded from serialized outputConsider adding edge case tests:
- A field with both
read_only=Trueandwrite_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
📒 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_onlyandwrite_onlyfields to theFieldstruct is implemented correctly with appropriate PyO3 getters.
53-54: Constructor updates are well implemented.The documentation clearly explains the behavior of
read_onlyandwrite_onlyfields, 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 theread_onlyandwrite_onlyparameters 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
Summary by CodeRabbit
read_onlyandwrite_onlyflags to serializer fields, allowing fields to be excluded from deserialization or serialization as appropriate.read_onlyandwrite_onlyflags in serializers.read_onlyandwrite_onlyfields during serialization and deserialization.