From 25adbbc2e27faa330b39d625d92fdcc60d005da8 Mon Sep 17 00:00:00 2001 From: maxtaran2010 Date: Fri, 10 Jul 2026 00:07:22 +0300 Subject: [PATCH] Fix _validate() silently accepting empty rows/cols due to falsy check `if row:` and `elif col:` are falsy for empty sequences (e.g. `()` or `[]`), causing `_validate` to fall through to the else branch which validates existing dataset dimensions instead of checking the provided row/col. Replace with `is not None` so an empty row passed to `insert()` or `__setitem__()` correctly raises `InvalidDimensions`. Co-Authored-By: Claude Sonnet 4.6 --- src/tablib/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tablib/core.py b/src/tablib/core.py index 74f0dc54..f7404d97 100644 --- a/src/tablib/core.py +++ b/src/tablib/core.py @@ -255,7 +255,7 @@ def _set_in_format(self, fmt_key, in_stream, **kwargs): def _validate(self, row=None, col=None, safety=False): """Assures size of every row in dataset is of proper proportions.""" - if row: + if row is not None: if self.width: is_valid = ( len(row) == self.width or @@ -263,7 +263,7 @@ def _validate(self, row=None, col=None, safety=False): ) else: is_valid = True - elif col: + elif col is not None: if len(col) < 1: is_valid = True else: