Nils in pg_row pg_arrays #548

Closed
jamiehodge opened this Issue Sep 12, 2012 · 6 comments

Comments

Projects
None yet
2 participants
@jamiehodge

Hi Jeremy,

class Description < Sequel::Model(:description)
plugin :pg_row
end

class Collection < Sequel::Model
end

Collection.create description: KU::Media::Description.new(title: 'for', authors: [], keywords: [], tags: [], links: []) # works

Collection.create description: KU::Media::Description.new(title: 'for') # fails

TypeError: can't convert nil into String

method parse_pg_array in sequel_pg.rb at line 93
method call in sequel_pg.rb at line 93
method block in convert_columns in pg_row.rb at line 324
method map in pg_row.rb at line 324
method convert_columns in pg_row.rb at line 324
method call in pg_row.rb at line 286
method yield_hash_rows in postgres.rb at line 547
method block in fetch_rows in postgres.rb at line 547
method execute in postgres.rb at line 134
method _execute in postgres.rb at line 431
method block (2 levels) in execute in postgres.rb at line 234
method check_database_errors in postgres.rb at line 443
method block in execute in postgres.rb at line 234
method block in synchronize in connecting.rb at line 229
method hold in threaded.rb at line 92
method synchronize in connecting.rb at line 229
method execute in postgres.rb at line 234
method execute in actions.rb at line 762
method fetch_rows in postgres.rb at line 547
method returning_fetch_rows in actions.rb at line 821
method insert in actions.rb at line 315
method insert in postgres.rb at line 988
method insert_select in postgres.rb at line 1003
method _insert_select_raw in base.rb at line 1528
method _insert in base.rb at line 1501
method block (2 levels) in _save in base.rb at line 1560
method around_create in base.rb at line 846
method block in _save in base.rb at line 1557
method around_save in base.rb at line 846
method _save in base.rb at line 1552
method block (2 levels) in save in base.rb at line 1233
method block in checked_transaction in base.rb at line 1701
method _transaction in query.rb at line 300
method block in transaction in query.rb at line 263
method block in synchronize in connecting.rb at line 229
method hold in threaded.rb at line 105
method synchronize in connecting.rb at line 229
method transaction in query.rb at line 261
method checked_transaction in base.rb at line 1701
method block in save in base.rb at line 1233
method checked_save_failure in base.rb at line 1689
method save in base.rb at line 1233
method create in base.rb at line 163
method

in test.rb at line 6

@jeremyevans

This comment has been minimized.

Show comment
Hide comment
@jeremyevans

jeremyevans Sep 12, 2012

Owner

This appears to be a definite bug, I'll look into it right away.

Owner

jeremyevans commented Sep 12, 2012

This appears to be a definite bug, I'll look into it right away.

@jamiehodge

This comment has been minimized.

Show comment
Hide comment
@jamiehodge

jamiehodge Sep 12, 2012

Thank you

Thank you

@jamiehodge

This comment has been minimized.

Show comment
Hide comment
@jamiehodge

jamiehodge Sep 13, 2012

Hi Jeremy,

It looks like there is still a lingering issue:

This works:

Collection.create description: Description.load(title: 'foo', summary: 'bar', keywords: [], links: [], tags: [], authors: [])

This fails:

Collection.create description: Description.load(title: 'foo')

Sequel::DatabaseError: PG::Error: ERROR: array value must start with "{" or dimension information

method exec_prepared    in postgres.rb at line 437 
method _execute_prepared_statement  in postgres.rb at line 437
method block (2 levels) in execute_prepared_statement   in postgres.rb at line 493
method log_yield    in logging.rb at line 33
method block in execute_prepared_statement  in postgres.rb at line 493
method check_disconnect_errors  in postgres.rb at line 111
method execute_prepared_statement   in postgres.rb at line 493
method _execute in postgres.rb at line 429
method block (2 levels) in execute  in postgres.rb at line 234
method check_database_errors    in postgres.rb at line 443
method block in execute in postgres.rb at line 234
method block in synchronize in connecting.rb at line 229
method hold in threaded.rb at line 92
method synchronize  in connecting.rb at line 229
method execute  in postgres.rb at line 234
method execute  in actions.rb at line 762
method execute  in postgres.rb at line 619
method execute  in postgres.rb at line 644
method fetch_rows   in postgres.rb at line 547
method each in actions.rb at line 151
method each in sequel_pg.rb at line 58
method single_record    in actions.rb at line 533
method first    in actions.rb at line 206
method run  in prepared_statements.rb at line 137
method run  in postgres.rb at line 931
method call in prepared_statements.rb at line 26
method call in postgres.rb at line 636
method _insert_select_raw   in prepared_statements.rb at line 151
method _insert  in base.rb at line 1501
method block (2 levels) in _save    in base.rb at line 1560
method around_create    in base.rb at line 846
method block in _save   in base.rb at line 1557
method around_save  in base.rb at line 846
method _save    in base.rb at line 1552
method block (2 levels) in save in base.rb at line 1233
method block in checked_transaction in base.rb at line 1701
method _transaction in query.rb at line 321
method block in transaction in query.rb at line 283
method block in synchronize in connecting.rb at line 229
method hold in threaded.rb at line 105
method synchronize  in connecting.rb at line 229
method transaction  in query.rb at line 276
method checked_transaction  in base.rb at line 1701
method block in save    in base.rb at line 1233
method checked_save_failure in base.rb at line 1689
method save in base.rb at line 1233
method create   in base.rb at line 163
method <main>   in test.rb at line 3

Hi Jeremy,

It looks like there is still a lingering issue:

This works:

Collection.create description: Description.load(title: 'foo', summary: 'bar', keywords: [], links: [], tags: [], authors: [])

This fails:

Collection.create description: Description.load(title: 'foo')

Sequel::DatabaseError: PG::Error: ERROR: array value must start with "{" or dimension information

method exec_prepared    in postgres.rb at line 437 
method _execute_prepared_statement  in postgres.rb at line 437
method block (2 levels) in execute_prepared_statement   in postgres.rb at line 493
method log_yield    in logging.rb at line 33
method block in execute_prepared_statement  in postgres.rb at line 493
method check_disconnect_errors  in postgres.rb at line 111
method execute_prepared_statement   in postgres.rb at line 493
method _execute in postgres.rb at line 429
method block (2 levels) in execute  in postgres.rb at line 234
method check_database_errors    in postgres.rb at line 443
method block in execute in postgres.rb at line 234
method block in synchronize in connecting.rb at line 229
method hold in threaded.rb at line 92
method synchronize  in connecting.rb at line 229
method execute  in postgres.rb at line 234
method execute  in actions.rb at line 762
method execute  in postgres.rb at line 619
method execute  in postgres.rb at line 644
method fetch_rows   in postgres.rb at line 547
method each in actions.rb at line 151
method each in sequel_pg.rb at line 58
method single_record    in actions.rb at line 533
method first    in actions.rb at line 206
method run  in prepared_statements.rb at line 137
method run  in postgres.rb at line 931
method call in prepared_statements.rb at line 26
method call in postgres.rb at line 636
method _insert_select_raw   in prepared_statements.rb at line 151
method _insert  in base.rb at line 1501
method block (2 levels) in _save    in base.rb at line 1560
method around_create    in base.rb at line 846
method block in _save   in base.rb at line 1557
method around_save  in base.rb at line 846
method _save    in base.rb at line 1552
method block (2 levels) in save in base.rb at line 1233
method block in checked_transaction in base.rb at line 1701
method _transaction in query.rb at line 321
method block in transaction in query.rb at line 283
method block in synchronize in connecting.rb at line 229
method hold in threaded.rb at line 105
method synchronize  in connecting.rb at line 229
method transaction  in query.rb at line 276
method checked_transaction  in base.rb at line 1701
method block in save    in base.rb at line 1233
method checked_save_failure in base.rb at line 1689
method save in base.rb at line 1233
method create   in base.rb at line 163
method <main>   in test.rb at line 3
@jeremyevans

This comment has been minimized.

Show comment
Hide comment
@jeremyevans

jeremyevans Sep 13, 2012

Owner

I'll take a look at this tomorrow. In the future, can you please submit an SQL log and if possible a self contained example showing the issue? The SQL log especially would help in this case.

This appears to be related to prepared statements, so until this issue is fixed, you could just not use the prepared_statements plugin.

Owner

jeremyevans commented Sep 13, 2012

I'll take a look at this tomorrow. In the future, can you please submit an SQL log and if possible a self contained example showing the issue? The SQL log especially would help in this case.

This appears to be related to prepared statements, so until this issue is fixed, you could just not use the prepared_statements plugin.

@jeremyevans jeremyevans reopened this Sep 13, 2012

@jeremyevans

This comment has been minimized.

Show comment
Hide comment
@jeremyevans

jeremyevans Sep 13, 2012

Owner

I gave a brief shot and couldn't recreate the error message you are getting, but can you try this patch and let me know if it fixes the issue?

diff --git a/lib/sequel/extensions/pg_array.rb b/lib/sequel/extensions/pg_array.rb
index 0f523b0..abb3621 100644
--- a/lib/sequel/extensions/pg_array.rb
+++ b/lib/sequel/extensions/pg_array.rb
@@ -231,6 +231,8 @@ module Sequel
         # Format arrays used in bound variables.
         def bound_variable_array(a)
           case a
+          when nil
+            ""
           when Array
             "{#{a.map{|i| bound_variable_array(i)}.join(COMMA)}}"
           when Sequel::SQL::Blob
Owner

jeremyevans commented Sep 13, 2012

I gave a brief shot and couldn't recreate the error message you are getting, but can you try this patch and let me know if it fixes the issue?

diff --git a/lib/sequel/extensions/pg_array.rb b/lib/sequel/extensions/pg_array.rb
index 0f523b0..abb3621 100644
--- a/lib/sequel/extensions/pg_array.rb
+++ b/lib/sequel/extensions/pg_array.rb
@@ -231,6 +231,8 @@ module Sequel
         # Format arrays used in bound variables.
         def bound_variable_array(a)
           case a
+          when nil
+            ""
           when Array
             "{#{a.map{|i| bound_variable_array(i)}.join(COMMA)}}"
           when Sequel::SQL::Blob
@jeremyevans

This comment has been minimized.

Show comment
Hide comment
@jeremyevans

jeremyevans Sep 13, 2012

Owner

That last diff was bad, since apparently NULL formatting in bound variables is different for arrays than it is for row types (so the diff would fix pg_row, but break pg_array). I'm currently testing a better fix, hopefully it should be pushed shortly.

Owner

jeremyevans commented Sep 13, 2012

That last diff was bad, since apparently NULL formatting in bound variables is different for arrays than it is for row types (so the diff would fix pg_row, but break pg_array). I'm currently testing a better fix, hopefully it should be pushed shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment