Commit 1e3b72f
committed
fix: merge field constraints across all metadata items
get_field_metadata returned the first field.metadata item matching
(PydanticMetadata, MaxLen) and stopped. Pydantic v2 spreads constraints
across several metadata items, so when a matching item without the
length or precision (for example a pattern or allow_inf_nan constraint)
precedes the item that carries max_length, max_digits, or decimal_places,
those values were silently dropped and the generated SQLAlchemy column
was unbounded (VARCHAR / NUMERIC with no length or precision).
Scan all matching metadata items and merge max_length, max_digits, and
decimal_places into a single result, keeping the first non-None value for
each attribute. Single-metadata fields are unaffected. Add a regression
test covering the order-dependent str and Decimal cases.
Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.com>1 parent 07b69be commit 1e3b72f
2 files changed
Lines changed: 30 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
199 | 199 | | |
200 | 200 | | |
201 | 201 | | |
| 202 | + | |
202 | 203 | | |
203 | 204 | | |
204 | | - | |
205 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
206 | 211 | | |
207 | 212 | | |
208 | 213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
0 commit comments