top of page

Did Your Preview Consume the Records Your Import Needed?

Oct 26
3 min read

An import logs a helpful preview of the first few records, then processes fewer records than expected. Another import counts all incoming rows before processing and subsequently sees no rows at all. The source file may be intact; the first pass through an iterator may have consumed the data the second pass expected.


This problem often appears after adding diagnostics to working code. A preview or count looks observational, but consuming a one-pass source changes what remains available.


Identify whether the input can be traversed again


Python’s iterator documentation defines an iterator as producing successive items and signaling exhaustion when finished. An exhausted iterator must remain exhausted. A reusable collection and a particular iterator over it are different things.


Ask what the function actually receives: a list, a generator, a file reader or another iterator. A name such as “rows” does not answer that question. Review the documented input contract and the object created by the caller.


Map every consumer of the input


List the preview, validation, counting, transformation and writing steps in their actual order. Mark which steps advance the same iterator. Include logging helpers and assertions; they can consume input even when their purpose sounds read-only.


Decide which result the workflow needs. If the entire dataset must be validated before any external write, the design needs an appropriate staging or buffering strategy. If streaming is acceptable, validation and processing may need to be coordinated in one pass with explicit handling of partial progress.


Illustrative example: a three-record preview


Suppose a synthetic source contains eight distinct record identifiers. A diagnostic helper reads the first three for a preview. The processing loop then receives only the remaining five because it continues from the same iterator.


The correction is not to reduce the expected count to five. Preserve the intended eight-record scope. A design may retain the previewed records and include them in subsequent processing, or create a separate permitted traversal of a stable source.


Illustrative example: counting exhausts everything


A different helper counts every row before handing the same iterator to the importer. The count reports eight, while the import loop sees zero. Both observations can be consistent with the iterator’s behavior.


Use a fixture with explicit identifiers and verify the final set of processed identifiers. A test that checks only the preliminary count will pass while the actual work remains undone.


Choose a strategy with visible tradeoffs


Materializing a bounded dataset into a list can make repeated traversal straightforward, but it introduces memory use. Set an acceptable size boundary rather than converting an arbitrarily large or unbounded stream without review.


Reopening a source may provide another traversal, but confirm that the source is stable and that reopening has no unwanted effect. A second query against changing business data can produce different records. A second network request may also carry costs or operational consequences.


For streaming work, consider combining the count, preview capture and transformation in one controlled pass. Keep the preview bounded and avoid retaining sensitive payloads merely to improve logs. The chosen approach should preserve the required processing scope, not just make the debugging output convenient.


Verify completeness at the business boundary


Run a small source containing zero, one and several distinct records. Check the preview, attempted records, accepted records and rejected records separately. A rejected record should have a documented outcome rather than disappear from the accounting.


Repeat the test with diagnostics enabled and disabled. The business result should be the same when logging is intended to be observational. If it differs, inspect the consumer sequence before blaming the source.


Use the CSV import reconciliation checklist to connect this language-level issue to a complete import result. The important evidence is that every intended record has an outcome, including the records someone inspected before processing began.


Editorial note


Prepared with AI assistance. Primary sources and the FutureOS article inventory were checked on October 26, 2026. Examples are illustrative, not customer results. FutureOS is described as being in prelaunch in its current introduction. This guide does not claim an available product feature, integration or service, and no independent expert review is claimed.


Comments


Commenting on this post isn't available anymore. Contact the site owner for more info.
bottom of page