Commit 4223288
authored
DEV: Correctly validate multiple uploads in object site setting (#36639)
# Bug
The Setup:
- Object site setting has 2 upload fields: UPLOAD_FIELD_1 and
UPLOAD_FIELD_2
- Frontend sends URLs for both fields to the backend
- Backend needs to convert URLs → IDs and validate them
## The Problem
Validation loop processes properties one by one:
### 1. Validate UPLOAD_FIELD_1
- Convert URL → ID (123)
- Check if ID is valid by querying: Upload.where(id:
fetch_all_upload_values)
- fetch_all_upload_values returns: [123, "http://mobile.png"] ← MIXED
TYPES!
- Query only finds Upload 123
- Cache valid_ids = [123] ← MEMOIZED
### 2. Validate UPLOAD_FIELD_2
- Convert URL → ID (456)
- Check if ID is valid using cached valid_ids
- valid_ids = [123] ← Still cached from step 1!
- ID 456 not in [123] → VALIDATION FAILS ❌
Why it failed: When validating the first upload, the validation logic
tried to fetch ALL upload values to check validity. But the second
upload was still a URL string, not an ID yet. This created a mixed array
[123, "http://..."] that couldn't be properly queried. The cached result
then excluded the second upload, causing it to fail validation.
# Fix
Convert ALL URLs → IDs in first pass, THEN validate everything in second
pass. Now when the validation queries run, all values are already
integers.1 parent 9d1bfb7 commit 4223288
File tree
2 files changed
+42
-12
lines changed- lib
- spec/lib
2 files changed
+42
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
83 | 90 | | |
84 | 91 | | |
85 | 92 | | |
| |||
101 | 108 | | |
102 | 109 | | |
103 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
104 | 120 | | |
105 | 121 | | |
106 | 122 | | |
| |||
137 | 153 | | |
138 | 154 | | |
139 | 155 | | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
| 156 | + | |
| 157 | + | |
152 | 158 | | |
153 | 159 | | |
154 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
800 | 800 | | |
801 | 801 | | |
802 | 802 | | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
803 | 827 | | |
804 | 828 | | |
805 | 829 | | |
| |||
0 commit comments