Skip to content

Fix dynamic column callable placeholders when adding rows - #671

Open
deepakganesh78 wants to merge 1 commit into
jazzband:masterfrom
deepakganesh78:fix/issue576-dynamic-row-placeholders
Open

Fix dynamic column callable placeholders when adding rows#671
deepakganesh78 wants to merge 1 commit into
jazzband:masterfrom
deepakganesh78:fix/issue576-dynamic-row-placeholders

Conversation

@deepakganesh78

Copy link
Copy Markdown

Fixes #576

Reproduction

On current master, appending a row that uses the registered dynamic-column callables as placeholders stores the function objects instead of calculating their values:

import tablib

data = tablib.Dataset()
data.extend([['Greg', 'Thorton'], ['Dave', 'Coutts'], ['Joshua', 'Ourisman']])

def dynamic_column(row):
    return row[-1].upper() + '!'

data.append_col(dynamic_column, 'Calculated')
data.append(('Brad', 'Montgomery', dynamic_column))
print(data[-1])
# master: ('Brad', 'Montgomery', <function dynamic_column ...>)

Root cause

Dataset.insert() only evaluates dynamic columns when an appended row is shorter than the dataset width. If callers pass the dynamic callable in the dynamic column position, the row is already the full width, so validation succeeds and the callable object is stored as data.

Fix

Before validation, full-width rows now resolve only placeholders that are exactly the registered dynamic-column function. The function is called with the current row minus that placeholder, preserving the existing behavior for shorter rows and for explicit non-callable dynamic values.

Compatibility notes

Existing partial-row dynamic column generation still works. Full rows with explicit computed dynamic values are unchanged; only cells that are the same function object registered for that dynamic column are evaluated.

Validation

  • Regression test with fix reverted: python -m pytest tests\\test_tablib.py::TablibTestCase::test_add_callable_column -q fails, storing function objects instead of ('Brad', 'Montgomery', 70, 'Brad', 'BM').
  • Targeted regression test with fix: 1 passed.
  • Full suite: TZ=UTC python -m pytest -> 183 passed.
  • Lint: python -m ruff check src\\tablib\\core.py -> All checks passed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dynamic elements when adding rows

1 participant