Bug report #14390
Layer id generation prone to collisisions and overwrite in asynchronous layer creation
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | - | ||
Category: | Python plugins | ||
Affected QGIS version: | 2.12.0 | Regression?: | No |
Operating System: | Easy fix?: | No | |
Pull Request or Patch supplied: | No | Resolution: | |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 22371 |
Description
In http://qgis.org/api/qgsmaplayer_8cpp_source.html#l00076 you can see the ID of a layer is generated by appending the current date to the layer name (with some minor verification applied). If several layers with the same name are created simultaneously, QGIS will assign them the same ID.
If they are later added to the map layer registry, only the last layer added to it will actually be in it, and will overwrite the previously 'stored' layer with that same ID.
I found this out while attempting to add similarly named layers to groups: checks failed when comparing the provided layer by it's id with the one stored in the map layer registry. The post (and what I found out, as the solution) is here:
http://gis.stackexchange.com/questions/180987/qgis-2-10-adding-layers-to-legend-groups-programatically-fails-ocassionally-wi/182424#182424
The solution I propose is to append an UUID in the ID instead of the date, to avoid this issue.
Associated revisions
Use uuid instead of timestamp when generating layer ids
Timestamps can result in duplicate layer ids when layers
are created rapidly or in different threads.
Fix #14390
History
#1 Updated by Giovanni Manghi almost 8 years ago
- Priority changed from Normal to High
#2 Updated by Giovanni Manghi over 7 years ago
- Crashes QGIS or corrupts data changed from Yes to No
- OS version deleted (
7) - Operating System deleted (
Windows) - Priority changed from High to Normal
- Status changed from Open to Feedback
Did anything changed in latest QGIS releases? Could you submit a patch?
#3 Updated by Giovanni Manghi over 7 years ago
- Status changed from Feedback to Open
- Description updated (diff)
#4 Updated by Giovanni Manghi over 7 years ago
- Easy fix? set to No
- Regression? set to No
#5 Updated by Nyall Dawson over 7 years ago
- % Done changed from 0 to 100
- Status changed from Open to Closed
Applied in changeset qgis|03bfe9bfbcd34f11c05c5a0398907865cc424d9c.