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: gracefully handle empty hstore in pgdialect #1010

Merged
merged 2 commits into from
Aug 29, 2024

Conversation

0rax
Copy link
Contributor

@0rax 0rax commented Jul 22, 2024

In the current implementation of hstore in github.com/uptrace/bun/dialect/pgdialect, an empty hstore is encoded properly in the database as '' but can not be retrieved.

It is handled properly for a var md map[string]string = nil when NULL is inserted in database and an empty map is returned when querying back the record, but when using a map[string]string{} it will insert '' (which is expected) but will fail with the following error:

sql: Scan error on column index 8, name "metadata": bun: can't parse hstore: ""

This PR make sure an empty hstore is handled gracefully in the hstoreParser as well as adds test cases for this issues in pgdialect itself (for the parser AND the appender) as well as in the internal/dbtest package.

This fix is relatively crucial to us, as we tend to store user defined metadata in hstore and it may happen that a user removes all key value pairs from there. Currently, we have to check if the changes made to a metadata field makes it empty and force the field to be null, being able to handle empty hstore gracefully at the database driver level would make our life quite easier here as it seems like a legitimate use of that type.

@vmihailenco vmihailenco merged commit 2f73d8a into uptrace:master Aug 29, 2024
4 checks passed
@vmihailenco
Copy link
Member

Thanks for fixing this.

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