[openstreetmap-website] Fix bug allowing created elements to reference deleted ones. (#992)

Matt Amos notifications at github.com
Sat Jun 13 08:41:10 UTC 2015


> @@ -248,6 +248,9 @@ def preconditions_ok?(good_members = [])
>        model = Kernel.const_get(m[0].capitalize)
>        # get the element with that ID
>        element = model.find_by(:id => m[1])
> +      # if found, lock the element to ensure it can't be deleted until
> +      # after the current transaction commits.
> +      element.lock!("for share") unless element.nil?

The rails docs seem to suggest that `lock!` reloads the row, so wouldn't cause a race condition. However, this means its doing two queries where one would be enough, so it's definitely worth making your change.

---
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/992/files#r32369050
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20150613/1d5c2490/attachment-0001.html>


More information about the rails-dev mailing list