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 primary key issues for shapefile import #646

Merged
merged 1 commit into from
Jun 9, 2022
Merged

Conversation

olsen232
Copy link
Collaborator

@olsen232 olsen232 commented Jun 9, 2022

  • Don't use FID as a primary key, don't do anything with FID
  • Use any other field as the primary key if specified, otherwise,
    generate a new primary key.
  • Make tests check both of these behaviours
  • Delete tests that convert GPKG to SHP files to use as test data -
    checked in equivalent test data. The auto-converted test data
    was bad anyway: it had lost the primary key columns.

Fix the PkGeneratingTableImportSource - it shouldn't modify the
schema of the delegate import-source that it wraps. (Modifying
the schema of an import-source in place is allowed, as long
as you only change the IDs of the columns - these IDs are
Kart-internal and so are arbitrary for an import-source until
and unless we align them to an existing table. But, other
modifications to the import-source schema - such as adding
a new auto_pk column - can cause the import-source to crash,
so this must be done at the outer wrapper class only - in
the PkGeneratingTableImportSource).

Checklist:

  • Have you reviewed your own change?
  • Have you included test(s)?
  • Have you updated the changelog?

- Don't use FID as a primary key, don't do anything with FID
- Use any other field as the primary key if required, otherwise,
  generate a new primary key.
- Make tests check both of these behaviours
- Delete tests that convert GPKG to SHP files to use as test data -
  checked in equivalent test data. The auto-converted test data
  was bad anyway: it had lost the primary key columns.

Fix the PkGeneratingTableImportSource - it shouldn't modify the
schema of the delegate import-source that it wraps. (Modifying
the schema of an import-source in place is allowed, as long
as you only change the IDs of the columns - these IDs are
Kart-internal and so are arbitrary for an import-source until
and unless we align them to an existing table. But, other
modifications to the import-source schema - such as adding
a new `auto_pk` column - can cause the import-source to crash,
so this must be done at the outer wrapper class only - in
the PkGeneratingTableImportSource).
if primary_key_name == self.ogrlayer.GetFIDColumn():
# OGR automatically turns 'ogc_fid' column in postgres into an FID,
# and removes it from the list of fields below.
self.use_ogc_fid_as_pk = True
Copy link
Member

Choose a reason for hiding this comment

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

Probably it shouldn't? We could set the PGSQL_OGR_FID config option to some random UUID to prevent it doing this. Then we could just treat an ogc_fid field as a regular field

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

... yeah we could do that. But we're not using this except for shapefiles right now so the comment is out of date and the behaviour for non-shapefiles isn't very important. I think best not to change this code too much unless it fixes a bug or we start using it for another OGR import type.

@olsen232 olsen232 merged commit 75ed5b0 into master Jun 9, 2022
@olsen232 olsen232 deleted the shapefile-fix branch June 9, 2022 21:44
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.

None yet

2 participants