{"issue":{"pull_request":{"diff_url":null,"html_url":null,"patch_url":null},"state":"closed","user":{"avatar_url":"https://secure.gravatar.com/avatar/d01b85a507aadb79d402e5efd1aa651f?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","gravatar_id":"d01b85a507aadb79d402e5efd1aa651f","url":"https://api.github.com/users/malclocke","login":"malclocke","id":169126},"milestone":null,"assignee":null,"labels":[],"updated_at":"2011-11-11T17:05:23Z","comments":2,"closed_at":"2011-11-11T17:05:23Z","url":"https://api.github.com/repos/markevans/dragonfly/issues/135","body":"Hi,\r\n\r\nRails 3.1.0\r\nDragonfly `5e953f803f90f9e1963c795c1baa94a0b9156746`\r\n\r\nI'm trying to backtrack to get a solution to this, but it's proving very elusive as I haven't yet come up with a guaranteed method of reproduction.  Am starting this ticket here in case anyone can shed any light on where I might look for extra clues.\r\n\r\nWe're running a Rails 3.1.0 app, with multiple models having multiple image fields using Dragonfly.  We have `validates_property` for all of the images, checking width and height.  Occasionally, a validation will fail because the `attachment.width` and or `attachment.height` checks return bad values.\r\n\r\nThe only way I can reproduce this is by running our test suite in a loop and waiting for a failure.  The failure points are seemingly completely random.\r\n\r\nHere's an example model:\r\n\r\n```ruby\r\n# Imageable consts are just integers\r\nclass Design < ActiveRecord::Base\r\n\r\n  image_accessor :image\r\n  image_accessor :thumbnail_image\r\n\r\n  validates_property :width,\r\n                     :of      => :image,\r\n                     :in      => (Imageable::MinimumPixels..Imageable::MaximumPixels),\r\n                     :message => :image_width_invalid\r\n\r\n  validates_property :height,\r\n                     :of      => :image,\r\n                     :in      => (Imageable::MinimumPixels..Imageable::MaximumPixels),\r\n                     :message => :image_height_invalid\r\n\r\n  validates_property :format,\r\n                     :of      => :image,\r\n                     :in      => Imageable::ValidFormats,\r\n                     :message => :image_format_invalid\r\n\r\n  validates_property :width,\r\n                     :of      => :thumbnail_image,\r\n                     :as      => Imageable::ThumbnailWidth,\r\n                     :message => :image_width_invalid\r\n\r\n  validates_property :height,\r\n                     :of      => :thumbnail_image,\r\n                     :as      => Imageable::ThumbnailHeight,\r\n                     :message => :image_height_invalid\r\n\r\n  validates_property :format,\r\n                     :of      => :thumbnail_image,\r\n                     :in      => Imageable::ValidFormats,\r\n                     :message => :image_format_invalid\r\n\r\nend\r\n\r\n```\r\n\r\nSo far, I've added the following debug:\r\n\r\n```diff\r\ndiff --git a/lib/dragonfly/active_model_extensions/validations.rb b/lib/dragonfly/active_model_extensions/validations.rb\r\nindex 236100e..8f3ccd1 100644\r\n--- a/lib/dragonfly/active_model_extensions/validations.rb\r\n+++ b/lib/dragonfly/active_model_extensions/validations.rb\r\n@@ -16,6 +16,12 @@ module Dragonfly\r\n           if attachment\r\n             property = attachment.send(property_name)\r\n             unless allowed_values.include?(property)\r\n+              puts \"Validation failed for #{model}##{attr}##{property_name}\"\r\n+              puts \"-> got #{property}: wanted: #{allowed_values.inspect}\"\r\n+              puts \"-> attachment model: #{attachment.instance_variable_get('@model')}\"\r\n+              puts \"-> meta: #{attachment.meta.inspect}\"\r\n+              puts \"-> width: #{attachment.width} height: #{attachment.height}\"\r\n+              puts attachment.inspect\r\n               message = opts[:message] ||\r\n                 \"#{property_name.to_s.humanize.downcase} is incorrect. \"+\r\n                 \"It needs to be #{Validations.expected_values_string(allowed_values)}\"+\r\n```\r\n\r\nand on the test failure I get this.  The image `1600x1200_152k.jpg` is the one expected on the model object in the test, but the value being returned for `width` and `height` (200px) is clearly wrong, and is coming from one of the other images.\r\n\r\nI'd appreciate any pointers to potential candidates that might be causing this, it's taking me a while to unpick the code path in the gem.\r\n\r\n```\r\nValidation failed for Design 3#image#width\r\n-> got 200: wanted: 1000..5000\r\n-> attachment model: Design 3\r\n-> meta: {:name=>\"1600x1200_152k.jpg\", :model_class=>\"Design\", :model_attachment=>:image}\r\n-> width: 200 height: 200\r\n<Dragonfly Attachment uid=nil, app=#<Dragonfly::App:0x00000006831a20 @generator=#<Dragonfly::Generator:0x0000000698f660 with functions: plain, plasma, text >, @encoder=#<Dragonfly::Encoder:0x00000006785ab8 with functions: encode >, @processor=#<Dragonfly::Processor:0x00000006814178 with functions: convert, crop, flip, flop, grayscale, greyscale, resize, resize_and_crop, rotate, strip, thumb >, @analyser=#<Dragonfly::Analyser:0x00000006997388 with functions: aspect_ratio, depth, format, height, image?, landscape?, mime_type, number_of_colors, number_of_colours, portrait?, width >, @child_configurables=[#<Dragonfly::Analyser:0x00000006997388 with functions: aspect_ratio, depth, format, height, image?, landscape?, mime_type, number_of_colors, number_of_colours, portrait?, width >, #<Dragonfly::Processor:0x00000006814178 with functions: convert, crop, flip, flop, grayscale, greyscale, resize, resize_and_crop, rotate, strip, thumb >, #<Dragonfly::Encoder:0x00000006785ab8 with functions: encode >, #<Dragonfly::Generator:0x0000000698f660 with functions: plain, plasma, text >, #<Dragonfly::Server:0x000000067892a8 @app=#<Dragonfly::App:0x00000006831a20 ...>, @log_object=#<Proc:0x00000006789190@/home/malc/wholemeal/projects/dragonfly/lib/dragonfly/loggable.rb:24>, @config_methods=[:allow_fetch_file, :allow_fetch_file=, :allow_fetch_url, :allow_fetch_url=, :dragonfly_url, :dragonfly_url=, :protect_from_dos_attacks, :protect_from_dos_attacks=, :url_format, :url_format=, :url_host, :url_host=, :before_serve], @fallback_configurable=#<Dragonfly::App:0x00000006831a20 ...>, @configuration={:log=>#<ActiveSupport::BufferedLogger:0x00000006846560 @level=0, @buffer={}, @auto_flushing=1, @guard=#<Mutex:0x00000006845a20>, @log=#<File:/home/malc/clients/xxx/xxx/log/test.log>>, :url_format=>\"/media/:job/:basename.:format\", :log_commands=>true}, @child_configurables=[], @default_configuration={:allow_fetch_file=>false, :allow_fetch_url=>false, :dragonfly_url=>\"/dragonfly\", :protect_from_dos_attacks=>false, :url_format=>\"/:job/:basename.:format\", :url_host=>nil}, @url_mapper=#<Dragonfly::UrlMapper:0x000000081f7bd0 @url_format=\"/media/:job/:basename.:format\", @segments=[#<struct Dragonfly::UrlMapper::Segment param=\"job\", seperator=\"/\", pattern=\"[\\\\w+~]\">, #<struct Dragonfly::UrlMapper::Segment param=\"basename\", seperator=\"/\", pattern=\"[^\\\\/]\">, #<struct Dragonfly::UrlMapper::Segment param=\"format\", seperator=\".\", pattern=\"[^\\\\.]\">], @url_regexp=/^\\/media(\\/[\\w+~]+?)?(\\/[^\\/]+?)?(\\.[^\\.]+?)?$/, @params_in_url=[\"job\", \"basename\", \"format\"]>>], @config_methods=[:datastore, :datastore=, :cache_duration, :cache_duration=, :fallback_mime_type, :fallback_mime_type=, :secret, :secret=, :log, :log=, :trust_file_extensions, :trust_file_extensions=, :content_disposition, :content_disposition=, :content_filename, :content_filename=, :job, :register_mime_type, :response_headers, :define_url, :url_path_prefix=, :url_suffix=, :infer_mime_type_from_file_ext=, :allow_fetch_file, :allow_fetch_file=, :allow_fetch_url, :allow_fetch_url=, :dragonfly_url, :dragonfly_url=, :protect_from_dos_attacks, :protect_from_dos_attacks=, :url_format, :url_format=, :url_host, :url_host=, :before_serve, :convert_command, :convert_command=, :identify_command, :identify_command=, :log_commands, :log_commands=, :supported_formats, :supported_formats=, :file_command, :file_command=, :use_filesystem, :use_filesystem=, :num_bytes_to_check, :num_bytes_to_check=], @server=#<Dragonfly::Server:0x000000067892a8 @app=#<Dragonfly::App:0x00000006831a20 ...>, @log_object=#<Proc:0x00000006789190@/home/malc/wholemeal/projects/dragonfly/lib/dragonfly/loggable.rb:24>, @config_methods=[:allow_fetch_file, :allow_fetch_file=, :allow_fetch_url, :allow_fetch_url=, :dragonfly_url, :dragonfly_url=, :protect_from_dos_attacks, :protect_from_dos_attacks=, :url_format, :url_format=, :url_host, :url_host=, :before_serve], @fallback_configurable=#<Dragonfly::App:0x00000006831a20 ...>, @configuration={:log=>#<ActiveSupport::BufferedLogger:0x00000006846560 @level=0, @buffer={}, @auto_flushing=1, @guard=#<Mutex:0x00000006845a20>, @log=#<File:/home/malc/clients/xxx/xxx/log/test.log>>, :url_format=>\"/media/:job/:basename.:format\", :log_commands=>true}, @child_configurables=[], @default_configuration={:allow_fetch_file=>false, :allow_fetch_url=>false, :dragonfly_url=>\"/dragonfly\", :protect_from_dos_attacks=>false, :url_format=>\"/:job/:basename.:format\", :url_host=>nil}, @url_mapper=#<Dragonfly::UrlMapper:0x000000081f7bd0 @url_format=\"/media/:job/:basename.:format\", @segments=[#<struct Dragonfly::UrlMapper::Segment param=\"job\", seperator=\"/\", pattern=\"[\\\\w+~]\">, #<struct Dragonfly::UrlMapper::Segment param=\"basename\", seperator=\"/\", pattern=\"[^\\\\/]\">, #<struct Dragonfly::UrlMapper::Segment param=\"format\", seperator=\".\", pattern=\"[^\\\\.]\">], @url_regexp=/^\\/media(\\/[\\w+~]+?)?(\\/[^\\/]+?)?(\\.[^\\.]+?)?$/, @params_in_url=[\"job\", \"basename\", \"format\"]>>, @job_definitions=#<Dragonfly::JobDefinitions:0x00000006763080>, @configuration={:log=>#<ActiveSupport::BufferedLogger:0x00000006846560 @level=0, @buffer={}, @auto_flushing=1, @guard=#<Mutex:0x00000006845a20>, @log=#<File:/home/malc/clients/xxx/xxx/log/test.log>>, :url_format=>\"/media/:job/:basename.:format\", :log_commands=>true}, @default_configuration={:datastore=>#<Dragonfly::DataStorage::FileDataStore:0x00000006a2a318 @root_path=\"/home/malc/clients/xxx/xxx/public/system/dragonfly/test\", @configuration={:root_path=>\"/home/malc/clients/xxx/xxx/public/system/dragonfly/test\", :server_root=>\"/home/malc/clients/xxx/xxx/public\"}, @child_configurables=[], @server_root=\"/home/malc/clients/xxx/xxx/public\", @default_configuration={:root_path=>\"/var/tmp/dragonfly\", :server_root=>nil, :store_meta=>true}>, :cache_duration=>31536000, :fallback_mime_type=>\"application/octet-stream\", :secret=>\"secret yo\", :log=>#<Dragonfly::Configurable::DeferredBlock:0x0000000577f3f8 @blk=#<Proc:0x0000000577f4e8@/home/malc/wholemeal/projects/dragonfly/lib/dragonfly/app.rb:47>>, :trust_file_extensions=>true, :content_disposition=>nil, :content_filename=>#<Proc:0x00000005579248@/home/malc/wholemeal/projects/dragonfly/lib/dragonfly/response.rb:6>}, @job_class=#<Class:0x00000007dd54f8>>>\r\nValidation failed for Design 3#image#height\r\n-> got 200: wanted: 1000..5000\r\n-> attachment model: Design 3\r\n-> meta: {:name=>\"1600x1200_152k.jpg\", :model_class=>\"Design\", :model_attachment=>:image}\r\n-> width: 200 height: 200\r\n<Dragonfly Attachment uid=nil, app=#<Dragonfly::App:0x00000006831a20 @generator=#<Dragonfly::Generator:0x0000000698f660 with functions: plain, plasma, text >, @encoder=#<Dragonfly::Encoder:0x00000006785ab8 with functions: encode >, @processor=#<Dragonfly::Processor:0x00000006814178 with functions: convert, crop, flip, flop, grayscale, greyscale, resize, resize_and_crop, rotate, strip, thumb >, @analyser=#<Dragonfly::Analyser:0x00000006997388 with functions: aspect_ratio, depth, format, height, image?, landscape?, mime_type, number_of_colors, number_of_colours, portrait?, width >, @child_configurables=[#<Dragonfly::Analyser:0x00000006997388 with functions: aspect_ratio, depth, format, height, image?, landscape?, mime_type, number_of_colors, number_of_colours, portrait?, width >, #<Dragonfly::Processor:0x00000006814178 with functions: convert, crop, flip, flop, grayscale, greyscale, resize, resize_and_crop, rotate, strip, thumb >, #<Dragonfly::Encoder:0x00000006785ab8 with functions: encode >, #<Dragonfly::Generator:0x0000000698f660 with functions: plain, plasma, text >, #<Dragonfly::Server:0x000000067892a8 @app=#<Dragonfly::App:0x00000006831a20 ...>, @log_object=#<Proc:0x00000006789190@/home/malc/wholemeal/projects/dragonfly/lib/dragonfly/loggable.rb:24>, @config_methods=[:allow_fetch_file, :allow_fetch_file=, :allow_fetch_url, :allow_fetch_url=, :dragonfly_url, :dragonfly_url=, :protect_from_dos_attacks, :protect_from_dos_attacks=, :url_format, :url_format=, :url_host, :url_host=, :before_serve], @fallback_configurable=#<Dragonfly::App:0x00000006831a20 ...>, @configuration={:log=>#<ActiveSupport::BufferedLogger:0x00000006846560 @level=0, @buffer={}, @auto_flushing=1, @guard=#<Mutex:0x00000006845a20>, @log=#<File:/home/malc/clients/xxx/xxx/log/test.log>>, :url_format=>\"/media/:job/:basename.:format\", :log_commands=>true}, @child_configurables=[], @default_configuration={:allow_fetch_file=>false, :allow_fetch_url=>false, :dragonfly_url=>\"/dragonfly\", :protect_from_dos_attacks=>false, :url_format=>\"/:job/:basename.:format\", :url_host=>nil}, @url_mapper=#<Dragonfly::UrlMapper:0x000000081f7bd0 @url_format=\"/media/:job/:basename.:format\", @segments=[#<struct Dragonfly::UrlMapper::Segment param=\"job\", seperator=\"/\", pattern=\"[\\\\w+~]\">, #<struct Dragonfly::UrlMapper::Segment param=\"basename\", seperator=\"/\", pattern=\"[^\\\\/]\">, #<struct Dragonfly::UrlMapper::Segment param=\"format\", seperator=\".\", pattern=\"[^\\\\.]\">], @url_regexp=/^\\/media(\\/[\\w+~]+?)?(\\/[^\\/]+?)?(\\.[^\\.]+?)?$/, @params_in_url=[\"job\", \"basename\", \"format\"]>>], @config_methods=[:datastore, :datastore=, :cache_duration, :cache_duration=, :fallback_mime_type, :fallback_mime_type=, :secret, :secret=, :log, :log=, :trust_file_extensions, :trust_file_extensions=, :content_disposition, :content_disposition=, :content_filename, :content_filename=, :job, :register_mime_type, :response_headers, :define_url, :url_path_prefix=, :url_suffix=, :infer_mime_type_from_file_ext=, :allow_fetch_file, :allow_fetch_file=, :allow_fetch_url, :allow_fetch_url=, :dragonfly_url, :dragonfly_url=, :protect_from_dos_attacks, :protect_from_dos_attacks=, :url_format, :url_format=, :url_host, :url_host=, :before_serve, :convert_command, :convert_command=, :identify_command, :identify_command=, :log_commands, :log_commands=, :supported_formats, :supported_formats=, :file_command, :file_command=, :use_filesystem, :use_filesystem=, :num_bytes_to_check, :num_bytes_to_check=], @server=#<Dragonfly::Server:0x000000067892a8 @app=#<Dragonfly::App:0x00000006831a20 ...>, @log_object=#<Proc:0x00000006789190@/home/malc/wholemeal/projects/dragonfly/lib/dragonfly/loggable.rb:24>, @config_methods=[:allow_fetch_file, :allow_fetch_file=, :allow_fetch_url, :allow_fetch_url=, :dragonfly_url, :dragonfly_url=, :protect_from_dos_attacks, :protect_from_dos_attacks=, :url_format, :url_format=, :url_host, :url_host=, :before_serve], @fallback_configurable=#<Dragonfly::App:0x00000006831a20 ...>, @configuration={:log=>#<ActiveSupport::BufferedLogger:0x00000006846560 @level=0, @buffer={}, @auto_flushing=1, @guard=#<Mutex:0x00000006845a20>, @log=#<File:/home/malc/clients/xxx/xxx/log/test.log>>, :url_format=>\"/media/:job/:basename.:format\", :log_commands=>true}, @child_configurables=[], @default_configuration={:allow_fetch_file=>false, :allow_fetch_url=>false, :dragonfly_url=>\"/dragonfly\", :protect_from_dos_attacks=>false, :url_format=>\"/:job/:basename.:format\", :url_host=>nil}, @url_mapper=#<Dragonfly::UrlMapper:0x000000081f7bd0 @url_format=\"/media/:job/:basename.:format\", @segments=[#<struct Dragonfly::UrlMapper::Segment param=\"job\", seperator=\"/\", pattern=\"[\\\\w+~]\">, #<struct Dragonfly::UrlMapper::Segment param=\"basename\", seperator=\"/\", pattern=\"[^\\\\/]\">, #<struct Dragonfly::UrlMapper::Segment param=\"format\", seperator=\".\", pattern=\"[^\\\\.]\">], @url_regexp=/^\\/media(\\/[\\w+~]+?)?(\\/[^\\/]+?)?(\\.[^\\.]+?)?$/, @params_in_url=[\"job\", \"basename\", \"format\"]>>, @job_definitions=#<Dragonfly::JobDefinitions:0x00000006763080>, @configuration={:log=>#<ActiveSupport::BufferedLogger:0x00000006846560 @level=0, @buffer={}, @auto_flushing=1, @guard=#<Mutex:0x00000006845a20>, @log=#<File:/home/malc/clients/xxx/xxx/log/test.log>>, :url_format=>\"/media/:job/:basename.:format\", :log_commands=>true}, @default_configuration={:datastore=>#<Dragonfly::DataStorage::FileDataStore:0x00000006a2a318 @root_path=\"/home/malc/clients/xxx/xxx/public/system/dragonfly/test\", @configuration={:root_path=>\"/home/malc/clients/xxx/xxx/public/system/dragonfly/test\", :server_root=>\"/home/malc/clients/xxx/xxx/public\"}, @child_configurables=[], @server_root=\"/home/malc/clients/xxx/xxx/public\", @default_configuration={:root_path=>\"/var/tmp/dragonfly\", :server_root=>nil, :store_meta=>true}>, :cache_duration=>31536000, :fallback_mime_type=>\"application/octet-stream\", :secret=>\"secret yo\", :log=>#<Dragonfly::Configurable::DeferredBlock:0x0000000577f3f8 @blk=#<Proc:0x0000000577f4e8@/home/malc/wholemeal/projects/dragonfly/lib/dragonfly/app.rb:47>>, :trust_file_extensions=>true, :content_disposition=>nil, :content_filename=>#<Proc:0x00000005579248@/home/malc/wholemeal/projects/dragonfly/lib/dragonfly/response.rb:6>}, @job_class=#<Class:0x00000007dd54f8>>>\r\n```\r\n","html_url":"https://github.com/markevans/dragonfly/issues/135","title":"Intermittent validation errors with Rails 3.1.0","number":135,"id":1907539,"created_at":"2011-10-14T04:07:20Z"},"action":"closed"}