Skip to content

Conversation

@jmichaelward
Copy link

This PR addresses an issue where running artisan etls:run <etl-name> --incremental against an empty database table will silently fail due to a mismatched return type in DbLoader::getIncrementalLastValue.

getIncrementalLastValue use's Laravel's Builder object to build a query against the configured connection, ultimately returning the result of the value call. This works when the destination database table already has data, because it returns the value of the last row in the configured column. However, when the database table is empty, the value call returns null, which is not what getIncrementalLastValue expects to return. The type is not converted and the extraction fails.

->orderByDesc($this->updateColumn)
->limit(1)
->value($this->updateColumn);
->value($this->updateColumn) ?? '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make more sense to return null|string ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely. I considered that, but hoped for this to cause the least amount of disruption. The if ($incremental) check correctly fails on an empty string, so everything else downstream runs correctly.

We could change the return type, but that would require additional refactors elsewhere and a version bump for anyone who might be using it (which is only us based on the repos I have access to, but I don't know what else is out there).

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.

2 participants