Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #7533 (closed defect: fixed)

Opened 2 years ago

Last modified 1 year ago

[PATCH] Fixes a small bug with the postgresql adapter's default value regex for text columns

Reported by: carllerche Assigned to: core
Priority: normal Milestone: 1.2.5
Component: ActiveRecord Version: edge
Severity: normal Keywords: postgresql adapter default
Cc: rein.henrichs@gmail.com, aguynamedryan@gmail.com

Description

This is a very simple bug fix. There is a minor quirk with how postgresql currently pulls default values for any text fields. It basically doesn't take into consideration the possibility of multiline default values (the current regex isn't a multiline regex). This especially causes trouble when you want to use serialize in an AR model and set a default class.

In the migration, you might put t.column :my_serialized_array, :text, :default => [].to_yaml

but the postgresql adapter won't pick up on it and AR will throw a whole bunch of exceptions because the serialized attribute isn't of the right type.

Attachments

postgresql_adapter_default_value_bug.diff (1.6 kB) - added by carllerche on 02/11/07 21:35:30.
postgresql_adapter_default_value_bug_2.diff (1.6 kB) - added by aguynamedryan on 04/12/07 22:07:20.
Builds off of carllerche's original test, but addresses escaping issue raised by ReinH
postgresql_adapter_default_value_bug.patch (1.6 kB) - added by tarmo on 10/08/07 05:42:35.
Updated for latest edge
postgresql_adapter_default_value_bug.2.patch (1.8 kB) - added by tarmo on 10/08/07 06:05:49.
New version with requested changes

Change History

02/11/07 21:35:30 changed by carllerche

  • attachment postgresql_adapter_default_value_bug.diff added.

02/17/07 08:34:56 changed by carllerche

Any word on this? Who maintains the postgresql adapter?

03/07/07 22:23:08 changed by ReinH

  • cc set to rein.henrichs@gmail.com.

This will not work for Postgres > 8.1 where the escape string syntax is used in defaults with escaped characters, ie E'--- []\012\012'. Regex for this syntax could be:

return $1 if value =~ /\AE?'(.*)'::(bpchar|text|character varying|bytea)\Z/m

This regex will catch the default but as far as I can tell the regex match is not escaped properly and the above string becomes "--- []\\012\\012" rather than "--- []\n\n"

04/12/07 22:07:20 changed by aguynamedryan

  • attachment postgresql_adapter_default_value_bug_2.diff added.

Builds off of carllerche's original test, but addresses escaping issue raised by ReinH

04/12/07 22:08:31 changed by aguynamedryan

  • cc changed from rein.henrichs@gmail.com to rein.henrichs@gmail.com, aguynamedryan@gmail.com.

I ran into this problem this morning. Anyway, I noticed in the PostgreSQLAdapter class has a method: unescape_binary which seems to take care of ReinH's issue. My patch (postgresql_adapter_default_value_bug_2.diff) works for me under Postgres 8.2

10/08/07 05:42:35 changed by tarmo

  • attachment postgresql_adapter_default_value_bug.patch added.

Updated for latest edge

10/08/07 05:44:03 changed by tarmo

I've updated the patch. Left out the "E" prefix support as rails currently does not seem to expect it, my postgresql does not seem to return it and if it really is a problem then it would probably require more changes outside the scope of this ticket.

10/08/07 06:05:49 changed by tarmo

  • attachment postgresql_adapter_default_value_bug.2.patch added.

New version with requested changes

10/08/07 06:17:56 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [7801]) PostgreSQL: support multiline default values. Closes #7533.