rails-sqlserver / activerecord-sqlserver-adapter

SQL Server Adapter For Rails
MIT License
968 stars 558 forks source link

Default BIT columns are not being set #1197

Closed snex closed 16 hours ago

snex commented 4 days ago

Issue

Default BIT columns are not being set

Expected behavior

If a column has a NOT NULL constraint and a default value is specified, then that default value should be used if the value was not set via the Rails model.

Actual behavior

NULL is being sent for the value, causing the database to throw an error and not create the record.

How to reproduce

Create a table with a column of type BIT with NOT NULL and a DEFAULT. Create a Rails model representing this table. Try to create a record without specifying the value for the column in question.

Details

Compile-time settings (established with the "configure" script)
                            Version: freetds v1.3.3
             freetds.conf directory: /etc
     MS db-lib source compatibility: yes
        Sybase binary compatibility: yes
                      Thread safety: yes
                      iconv library: yes
                        TDS version: auto
                              iODBC: no
                           unixodbc: yes
              SSPI "trusted" logins: no
                           Kerberos: yes
                            OpenSSL: no
                             GnuTLS: yes
                               MARS: yes
snex commented 4 days ago

Seems to be happening for all column types, not just BIT.

aidanharan commented 20 hours ago

Could you create a test-case using the script in https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/wiki/How-to-report-a-bug#minimal-reproducible-script and attach it to this issue?

snex commented 16 hours ago

It looks like this is a permissions problem - the user we are connecting with does not have proper view permissions on the table. It can see most of the table structure but not what the defaults should be, so the adapter is confused into thinking there are none. I think this should be safe to close. Thank you.