Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return type error when running incremental on first time ETL. #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

@@ -306,6 +306,6 @@ public function getIncrementalLastValue(): string
->whereNotNull($this->updateColumn)
->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