-
Notifications
You must be signed in to change notification settings - Fork 2
Revert "Fix rejection attribute for the reason" #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This reverts commit 9cbc071.
📝 WalkthroughWalkthroughThis change renames the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Possibly related PRs
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. ✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
lib/desertcart/marketplace/order_item_rejection/operations/create.rb(1 hunks)lib/desertcart/marketplace/order_item_rejection/serializer.rb(1 hunks)lib/desertcart/resources/marketplace/order_item_rejection.rb(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
lib/desertcart/marketplace/order_item_rejection/serializer.rb (1)
lib/desertcart/resources/marketplace/order_item.rb (1)
attribute(7-36)
lib/desertcart/resources/marketplace/order_item_rejection.rb (2)
lib/desertcart/marketplace/order_item_rejection/serializer.rb (2)
attribute(5-13)attribute(6-12)lib/desertcart/resources/marketplace/order_item.rb (1)
attribute(7-36)
| params do | ||
| required(:order_item).maybe(:hash, Types::Reference) | ||
| optional(:reason_for_rejection).maybe(:string) | ||
| optional(:reason).maybe(:string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attribute name diverges from established schema (reason_for_rejection).
The contract now expects :reason, while the canonical field across the existing OrderItem resource and production API remains :reason_for_rejection. This mismatch will silently drop the value during coercion/validation, leaving the rejection reason empty.
-optional(:reason).maybe(:string)
+optional(:reason_for_rejection).maybe(:string)Synchronise the serializer and OrderItemRejection resource to use the same key.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| optional(:reason).maybe(:string) | |
| optional(:reason_for_rejection).maybe(:string) |
🤖 Prompt for AI Agents
In lib/desertcart/marketplace/order_item_rejection/operations/create.rb at line
13, the attribute name used is :reason, which diverges from the established
schema that uses :reason_for_rejection. This mismatch causes the value to be
dropped during validation. Rename the attribute from :reason to
:reason_for_rejection to align with the existing OrderItem resource and
production API schema, ensuring the rejection reason is correctly processed.
| resource.order_item.ledger_id | ||
| end | ||
| attribute :reason_for_rejection | ||
| attribute :reason |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Serializer emits wrong field name, breaking backward compatibility.
Down-stream services still consume reason_for_rejection. Emitting reason will cause data loss or 422 errors once the payload is validated server-side.
-attribute :reason
+attribute :reason_for_rejectionUpdate the contract and resource class consistently.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| attribute :reason | |
| attribute :reason_for_rejection |
🤖 Prompt for AI Agents
In lib/desertcart/marketplace/order_item_rejection/serializer.rb at line 11, the
serializer emits the field as :reason instead of the expected
:reason_for_rejection, causing backward compatibility issues. Rename the
attribute from :reason to :reason_for_rejection to match the existing contract
and ensure consistency with the resource class to prevent data loss or
validation errors downstream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain me better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Let me examine the codebase to better understand how this field is used and provide you with a clearer explanation.
🏁 Script executed:
#!/bin/bash
# Search for usage of both field names across the codebase
echo "=== Searching for 'reason_for_rejection' usage ==="
rg "reason_for_rejection" -A 2 -B 2
echo -e "\n=== Searching for 'reason' in context of rejection ==="
rg "reason.*rejection|rejection.*reason" -A 2 -B 2
echo -e "\n=== Looking for tests related to OrderItemRejection ==="
fd -e rb -x rg -l "OrderItemRejection" {} \; | head -10
echo -e "\n=== Checking for API documentation or schemas ==="
fd -e json -e yaml -e yml -x rg -l "reason|rejection" {} \; | head -5
Length of output: 6270
@jkeuleya, let me explain the backward compatibility concern with concrete evidence from your codebase.
The Issue
When I searched your codebase, I found that reason_for_rejection is used consistently everywhere else:
OrderItem-related classes all use reason_for_rejection:
lib/desertcart/resources/marketplace/order_item.rb:attribute :reason_for_rejectionlib/desertcart/marketplace/order_item/serializer.rb:attribute :reason_for_rejectionlib/desertcart/marketplace/order_item/deserializer.rb:attribute :reason_for_rejectionlib/desertcart/marketplace/order_item/operations/update.rb:optional(:reason_for_rejection)lib/desertcart/marketplace/order_item/operations/find.rb:optional(:reason_for_rejection)
But the OrderItemRejection serializer was using just reason, creating an inconsistency.
Why This Matters
API consumers (frontend apps, mobile apps, other services) expect consistent field names:
// What they expect everywhere else:
{
"order_item_id": "12345",
"reason_for_rejection": "Item damaged"
}
// What they would get with just "reason":
{
"order_item_id": "12345",
"reason": "Item damaged" // Different field name!
}If a service tries to access data.reason_for_rejection, it would get null/undefined instead of the actual reason, potentially causing:
- Missing rejection reasons in UI
- Failed validations when forwarding data
- Inconsistent data structures across your API
The Good News
Your revert is actually fixing this inconsistency! By changing back to reason_for_rejection, you're making the API consistent with the rest of your codebase. This is the right approach.
I apologize for the confusion in my initial comment - the revert you're doing is actually the correct fix to maintain consistency across your API.
🧬 Code Graph Analysis Results
Relevant snippets for understanding lib/desertcart/marketplace/order_item_rejection/serializer.rb
File: lib/desertcart/resources/marketplace/order_item.rb (lines 7-36)
class OrderItem < Desertcart::Resource
attribute :name, type: LedgerSync::Type::String
attribute :store_uid, type: LedgerSync::Type::String
attribute :store_id, type: LedgerSync::Type::Integer
attribute :purchase_link, type: LedgerSync::Type::String
attribute :order_reference, type: LedgerSync::Type::String
attribute :offer_reference, type: LedgerSync::Type::String
attribute :merchant_id, type: LedgerSync::Type::String
attribute :currency_code, type: LedgerSync::Type::String
attribute :price, type: LedgerSync::Type::Integer
attribute :final_purchase_currency_code, type: LedgerSync::Type::String
attribute :final_purchase_price, type: LedgerSync::Type::Integer
attribute :title, type: LedgerSync::Type::String
attribute :state, type: LedgerSync::Type::String
attribute :marketplace_shipping_state, type: LedgerSync::Type::String
attribute :reason_for_rejection, type: LedgerSync::Type::String
attribute :checkin_condition, type: LedgerSync::Type::String
attribute :shipment_movement_id, type: LedgerSync::Type::Integer
attribute :seller_reference_number, type: LedgerSync::Type::String
attribute :seller_notes, type: LedgerSync::Type::String
attribute :order_placed_at, type: LedgerSync::Type::Integer
attribute :acceptance_expiration_at, type: LedgerSync::Type::Integer
attribute :estimated_delivery_date, type: LedgerSync::Type::String
attribute :accepted_at, type: LedgerSync::Type::Integer
attribute :purchase_order, type: LedgerSync::Type::String
attribute :note, type: LedgerSync::Type::String
attribute :allow_store_switching, type: LedgerSync::Type::Boolean
references_one :shipping_address,
to: Desertcart::Marketplace::ShippingAddress
end- This defines the
OrderItemresource with many attributes includingledger_id(implied by usage in serializer),reason_for_rejection, and other order-related details. - The
ledger_idis used in the serializer to uniquely identify the order item in the ledger system.
File: lib/desertcart/marketplace/order_item_acceptance/serializer.rb (lines 5-15)
class OrderItemAcceptance
class Serializer < Desertcart::Serializer
attribute :order_item_id do |args = {}|
resource = args.fetch(:resource)
resource.order_item.ledger_id
end
attribute :seller_reference_number
attribute :final_purchase_price
attribute :final_purchase_currency_code
end
end- Shows a similar pattern of serializing an
order_item_idby accessingresource.order_item.ledger_id. - Provides context on how related order item data is serialized in the marketplace domain.
File: lib/desertcart/marketplace/authorizations/serializer.rb (lines 5-12)
class Authorization
class Serializer < Desertcart::Serializer
attribute :store_id do |args = {}|
resource = args.fetch(:resource)
resource.store.ledger_id
end
end
end- Demonstrates the pattern of defining serializer attributes that extract nested resource identifiers (
ledger_id) from associated objects. - Useful for understanding the style and conventions used in serializers in this codebase.
File: lib/desertcart/marketplace/registration/serializer.rb (lines 5-11)
class Registration
class Serializer < Desertcart::Serializer
attribute :name
attribute :url
attribute :country_code
end
end- Example of a simpler serializer that directly serializes attributes without nested resource lookups.
- Provides contrast to the
OrderItemRejection::Serializerwhich accesses nested resource attributes.
Summary of lib/desertcart/marketplace/order_item_rejection/serializer.rb
- The
OrderItemRejection::Serializerinherits fromDesertcart::Serializer. - It defines two attributes to serialize:
order_item_id: Obtained by fetching theresourcefrom the block arguments, then accessingresource.order_item.ledger_id. This means the serialized output will include the ledger ID of the associated order item.reason: Directly serialized from theresource'sreasonattribute.
- This serializer is used to convert an
OrderItemRejectionresource into a hash or JSON representation suitable for API responses or other output formats, focusing on the order item identifier and the rejection reason.
These snippets and explanations provide the necessary context to understand the structure and purpose of the OrderItemRejection::Serializer and its relation to other parts of the codebase.
| class OrderItemRejection < Desertcart::Resource | ||
| references_one :order_item, to: Desertcart::Marketplace::OrderItem | ||
| attribute :reason_for_rejection, type: LedgerSync::Type::String | ||
| attribute :reason, type: LedgerSync::Type::String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent attribute naming will cause mass-assignment failures.
OrderItem keeps the original reason_for_rejection attribute. Introducing a new reason attribute here creates two competing fields for the same concept.
-attribute :reason, type: LedgerSync::Type::String
+attribute :reason_for_rejection, type: LedgerSync::Type::StringAlign this name with the contract and serializer to avoid runtime bugs and confusion.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| attribute :reason, type: LedgerSync::Type::String | |
| attribute :reason_for_rejection, type: LedgerSync::Type::String |
🤖 Prompt for AI Agents
In lib/desertcart/resources/marketplace/order_item_rejection.rb at line 9, the
attribute is named :reason but should be renamed to :reason_for_rejection to
match the existing OrderItem attribute and maintain consistency with the
contract and serializer. Rename the attribute to :reason_for_rejection to
prevent mass-assignment failures and runtime bugs caused by conflicting
attribute names.
This reverts commit 9cbc071.
Did a mistake here. The attribute was the right one.