Bug report #14390

Layer id generation prone to collisisions and overwrite in asynchronous layer creation

Added by Harold Hormaechea about 8 years ago. Updated almost 7 years ago.

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


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:

The solution I propose is to append an UUID in the ID instead of the date, to avoid this issue.

Associated revisions

Revision 03bfe9bf
Added by Nyall Dawson almost 7 years ago

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


#1 Updated by Giovanni Manghi about 7 years ago

  • Priority changed from Normal to High

#2 Updated by Giovanni Manghi about 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 almost 7 years ago

  • Status changed from Feedback to Open
  • Description updated (diff)

#4 Updated by Giovanni Manghi almost 7 years ago

  • Easy fix? set to No
  • Regression? set to No

#5 Updated by Nyall Dawson almost 7 years ago

  • % Done changed from 0 to 100
  • Status changed from Open to Closed

Also available in: Atom PDF