-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Error in gdal.VectorTranslate for explodecollections=True + some weird python logging behaviour #8523
Comments
I can reproduce the issue(s), I have a question about the expected behavior though: the insert is failing because of the unique constraint violation and this is expected but an (unexpected?) consequence is that the output table is not created either, which leads to the second error when the dataset cache is flushed and the driver attempts to create the triggers on the non-existent table. The interaction between CPL_DEBUG and the exceptions is IMO a separate issue. |
we should disable the fid preservation when explodecollections is specified (ie opt automatically for unsetFid mode) |
Agreed, should we issue a warning in this case? Or just a debug msg? |
We should probably error out if both -preserve_fid and -explode_collections are specified. And if -explode_collections is specified, but neither -preserved_fid nor -unsetFid, a CPLDebug() will be sufficient |
From user perspective there should be one more option When it comes to SQL I believe that it is impossible to predict if the query will make duplicate fids. User should also in that case get an understandable error message. However, I cannot discover any good example about such query. |
I'd argue we have enough options already related to FID and ogr2ogr code is already super tricky, so I'm -0 on adding a new one for that case
I would be perfectly fine with the workaround. explodeCollections + preserving fid is very advanced usage. I'd suggest to just add a note in the doc of -explodeCollections in ogr2ogr doc page to use the above type of SQL if FID preservation in some form is desired. |
After a second thought I agree. Note in the documentation is enough. By a quick search from gis.exchange I found one question that clearly deals with fids which were duplicated and user did not understand why. |
Sounds all great! Thanks for looking into this.
I think there are indeed 3 +- seperate problems, but because it is a single case to reproduce them all, I opted to put them together in one issue. |
Oops, now the testcase doesn't work anymore for the other 2 issues? Especially the 3rd is quite annoying and is probably a general issue also in other situations, but the second would have been great to understand why this was happening as well, because probably also applicable in other situations. |
@theroggy would you please open a new ticket for the other issues (you can link to this one for the details)? Having "atomic" tickets simplifies developers work. |
Expected behavior and actual behavior.
This issue raises several things that could be improved:
gdal.VectorTranslate
is used on a gpkg file containing multipolygons withexplodeCollections=True
, the default behaviour is to preserve the fid's. However, whenexplodecollections
is being applied, normally is will be impossible to preserve fid's because duplicate fid's will appear. So, an error is thrown.Steps to reproduce the problem.
Code snippet
When gdal.UseExceptions() is called and "CPL_DEBUG" is not set
Like this, an exception is thrown, but it doesn't contain the error needed to understand the problem.
The error thrown is
RuntimeError: sqlite3_exec(CREATE TRIGGER "trigger_delete_feature_count_parcels" AFTER DELETE ON "parcels" BEGIN UPDATE gpkg_ogr_contents SET feature_count = feature_count - 1 WHERE lower(table_name) = lower('parcels'); END;) failed: no such table: main.parcels
The useful error to be thrown would be
ERROR 1: failed to execute insert : UNIQUE constraint failed: parcels.fid
When gdal.UseExceptions() is NOT called but "CPL_DEBUG" is set to "ON"
Like this, the logging is OK, but no exception thrown (logically).
When gdal.UseExceptions() is called AND "CPL_DEBUG" is set to "ON"
With this combo, the logging stops being written before the interesting stuff happend and no exception is thrown.
Operating system
Windows 10
GDAL version and provenance
Version 3.7.2 installed via conda-forge.
The text was updated successfully, but these errors were encountered: