format-sql icon indicating copy to clipboard operation
format-sql copied to clipboard

TypeError: expected a character buffer object

Open hut8 opened this issue 10 years ago • 2 comments

  File "/usr/local/bin/format-sql", line 11, in <module>                                                                                                      
    sys.exit(main())                                                                                                                                          
  File "/usr/local/lib/python2.7/dist-packages/format_sql/main.py", line 83, in main                                                                          
    _write_back(filename, lines, args.dry_run)                                                                                                                
  File "/usr/local/lib/python2.7/dist-packages/format_sql/main.py", line 148, in _write_back                                                                  
    f.write(lines)                                                                                                                                            
TypeError: expected a character buffer object       

I've tried this with several files, including one ruby file with embedded SQL and then just with the SQL itself. Any insight into this? I'm just surprised that others aren't getting the same error.

hut8 avatar Oct 21 '15 05:10 hut8

I get this error too. The troubling part is that when this happens it truncates the source file:

~/code/ruby >ll /tmp/x.sql
-rw-r--r--  1 skyes  wheel   965B Sep  6 15:05 /tmp/x.sql
~/code/ruby/gettxt-test >format-sql /tmp/x.sql
/tmp/x.sql

Traceback (most recent call last):
  File "/usr/local/bin/format-sql", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/format_sql/main.py", line 83, in main
    _write_back(filename, lines, args.dry_run)
  File "/usr/local/lib/python2.7/site-packages/format_sql/main.py", line 148, in _write_back
    f.write(lines)
TypeError: expected a string or other character buffer object
~/code/ruby/gettxt-test >ll /tmp/x.sql
-rw-r--r--  1 skyes  wheel     0B Sep  6 15:06 /tmp/x.sql

😱 🙀 :rage4:

~/code/ruby >python --version
Python 2.7.11
~/code/ruby >format-sql --version
format-sql 0.12.0

sshaw avatar Sep 06 '16 19:09 sshaw

Ran into this as well. I created https://github.com/paetzke/format-sql/pull/6 which I believe fixes the issue.

astahlman avatar Dec 21 '16 18:12 astahlman