]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/relation.rb
Fixed precondition failed message which was trying to dereference nil.
[rails.git] / app / models / relation.rb
index b66d957b90ae3bdb5827accab6a9ed28f2642f40..2619a545a31f647b4727a8d14867d9063972b4b4 100644 (file)
@@ -218,6 +218,11 @@ class Relation < ActiveRecord::Base
     # in the hash to be overwritten.
     raise OSM::APIDuplicateTagsError.new("relation", self.id, k) if @tags.include? k
 
+    # check tag size here, as we don't create a RelationTag object until
+    # just before we save...
+    raise OSM::APIBadUserInput.new("Relation #{self.id} has a tag with too long a key, '#{k}'.") if k.length > 255
+    raise OSM::APIBadUserInput.new("Relation #{self.id} has a tag with too long a value, '#{k}'='#{v}'.") if v.length > 255
+
     @tags[k] = v
   end
 
@@ -298,20 +303,17 @@ class Relation < ActiveRecord::Base
         # use reflection to look up the appropriate class
         model = Kernel.const_get(m[0].capitalize)
         # get the element with that ID
-        element = model.find(m[1])
+        element = model.find(:first, :conditions =>["id = ?", m[1]])
 
         # and check that it is OK to use.
         unless element and element.visible? and element.preconditions_ok?
-          raise OSM::APIPreconditionFailedError.new("Relation with id #{self.id} cannot be saved due to #{m[0]} with id #{element.id}")
-          return false
+          raise OSM::APIPreconditionFailedError.new("Relation with id #{self.id} cannot be saved due to #{m[0]} with id #{m[1]}")
         end
         hash[m[1]] = true
       end
     end
 
     return true
-  rescue
-    return false
   end
 
   # Temporary method to match interface to nodes