[Pg] Handle Data Type Conflicts in parseEWKB #5110
Open
+1,047
−521
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Bug (#2788)
When using the query API to interact with a postgres database, irrespective of the driver, I was always getting an error about the offset being out of bounds of the DataView. I was typically working around it by using the select APIs instead.
The Cause
During my investigation, I found out that the cause of the issue was a data contract violation in the
parseEWKBfunction in the filedrizzle-orm/src/pg-core/columns/postgis_extension/utils.ts. The function was expecting that the value passed to it would always be a hex string but I found out that was not the case. During testing, I discovered that there were cases where a GeoJSON object was passed to it instead.Therefore, I added a function to validate that the input is in fact a hex string before processing the content as a hex string. I also added support for directly using GeoJSON object strings and GeoJSON objects.
Testability
In order to ensure backward compatibility and confirm that the fixes did work, I augmented the integration tests in the
integration-tests/tests/extensions/postgis/postgres.test.tsandintegration-tests/tests/extensions/postgis/pg.test.ts. The included test cases cover query for tables containing geometry data and queries with relations for tables containing geometry data.I can confirm that these tests both completed successfully as shown in the image below.
Next Steps
While this pull request technically does "fix" #2788, it is nothing more than a patch or a hot fix. It does not really try to find out the root cause and just addresses the issues that exist at the surface.
I made this PR because I use drizzle a lot because I love it, and I know first hand how much of a pain this issue creates. I wanted to at least provide a quick fix for all of the other people that are using drizzle in production like me and are impeded by this issue like myself.
Conclusion
Please do not hesitate to reach out to me if you have any questions or comments you have for me. I would be delighted to provide my support in any meaningful capacity.