[BUG] Aws::Record::ItemCollection intermittently returns nil/raises from to_a and each
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 48/100
Hướng nghiên cứu
Bắt đầu với aws-record-2.14.0/lib/aws-record/record/item_collection.rb, đặc biệt là each ở dòng 28, và tái hiện lỗi bằng Model.build_query.complete! rồi đến to_a hoặc each. Theo dõi cách collection nhận Aws::PageableResponse của nó và kiểm tra đường dẫn each_page nil được báo cáo. Hoàn tất khi các truy vấn DynamoDB thành công luôn có thể được liệt kê mà không có kết quả nil hoặc exception.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the feature
Please harden Aws::Record::ItemCollection so it always honors the Enumerable contract. Today, calling to_a or each on a collection returned by Model.build_query.complete! can either raise or return nil, even when DynamoDB succeeded. The library should guarantee that enumerating a query result never blows up unless the service call itself failed.
Use Case
Every app using aws-record expects query.complete! to behave like a normal enumerable. In production we see sporadic NoMethodError: undefined method 'each_page' for nil:NilClass and cases where collection.to_a literally returns nil. That breaks paging, query helpers, and forces us to wrap every call site in defensive code just to prevent random 500s.
Proposed Solution
Ensure ItemCollection#each always has a backing Aws::PageableResponse and never returns nil.
Concretely:
- Don’t mutate @items out from under each; memoize the client response before iterating.
- Guard items.each_page with a lazy initializer so it never operates on nil.
- Consider adding internal retries if the SDK hasn’t populated the items accessor yet.
As an immediate workaround we had to wrap the result:
def safe_array(result)
Array(result.to_a)
rescue StandardError
result.each_with_object([]) { |item, memo| memo << item }
rescue StandardError
[]
end
…but that’s brittle and doesn’t belong in every consumer.
Other Information
NoMethodError: undefined method `each_page' for nil:NilClass
aws-record-2.14.0/lib/aws-record/record/item_collection.rb:28:in `each'
(ruby) enumerable.rb:225:in `to_a'
- Repro snippet:
collection = MyModel.build_query
.on_index(:class_gsi)
.key_expr(':tenant_and_class = ?', 'tenant-1#MY_MODEL')
.complete!
collection.to_a # randomly raises or returns nil
If aws-record embraced ActiveModel::Attributes (per issue #152), the enumerable bug would be a lot less painful to work around because:
- Every attribute read/write would flow through Rails’ attribute stack, so you could normalize/
sanitize values before they touch Dynamo’s marshalers—no need for custom “safe_to_a” guards
sprinkled across the codebase. - You’d get ActiveModel’s dirty tracking and coercion for free, which means your
Aws::Record::ItemCollection could just emit proper ActiveModel instances; they’d behave
identically to ActiveRecord rows when enumerated, making it easier for the SDK team to reuse
proven enumerable implementations. - Upstream fixes to ActiveModel types (e.g., handling nil serialization, type-casting edge cases)
would land automatically, shrinking the surface area where the Dynamo-specific enumerable can go
off the rails.
So, implementing the AMS attribute layer first would not only unlock normalization, it would also
simplify the SDK internals enough that bugs like the broken enumerable become much easier (maybe
even unnecessary) to patch.
Acknowledgements
- I may be able to implement this feature request
- This feature might incur a breaking change
aws-sdk-ruby-record version used
Ruby 3.4.4, aws-record 2.14.0, aws-sdk-dynamodb 1.176.x.
- Ngôn ngữ chính
- Ruby
- Star
- 318
- Fork
- 44
- Merge trung bình
- 3 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 4
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws/aws-record-ruby
-
BuildableSearch#complete!.to_a auto-paginates silently and Limit is per-page (companion to #153)Đang mởfeature-request
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
aws/aws-record-ruby#157 · 2 bình luận ·
-
feature-request
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 38/100
aws/aws-record-ruby#155 · 1 bình luận ·
-
feature-request
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
aws/aws-record-ruby#152 · 3 bình luận ·
-
feature-request
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
aws/aws-record-ruby#147 · 1 bình luận ·
-
feature-request
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
aws/aws-record-ruby#142 · 6 bình luận ·
Tất cả issue của aws/aws-record-ruby
Issue tương tự
-
主催者以外(未ログイン含む)でもイベントを中止できてしまうĐang mởbug priority: high
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
mitakarb/beerkeeper#1259 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
agent:triaged bug bughunt pm:bundler priority:p1
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
SocketDev/socket-patch#1125 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
ecosyste-ms/funds#711 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
clouflaure de fernandoĐang mởenhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
cloudflare/mcp#271 ·
Maintainer thường phản hồi trong vòng 1 ngày