Letractively / rubycas-server

Automatically exported from code.google.com/p/rubycas-server
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Ticket type is NULL with active_record 2.0.0+ #37

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
1. Install RubyCAS server 0.5.1 and ActiveRecord 2.0.2 configured to use
PostgreSQL adapter
2. Try to authorize

I receive the following exception:

Camping Problem!
CASServer::Controllers::Login.POST
ActiveRecord::StatementInvalid PGError: ERROR: null value in column "type"
violates not-null constraint : INSERT INTO casserver_st ("created_on",
"ticket", "service", "type", "username", "proxy_granting_ticket_id",
"client_hostname", "consumed") VALUES('2008-02-21 16:38:46.059178',
E'ST-1203593926r62ADFD4B3FBC8D3BCB', E'http://localhost/', NULL, E'dekart',
NULL, E'127.0.0.1', NULL):

    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/connection_ada
pters/abstract_adapter.rb:150:in
`log'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/connection_ada
pters/postgresql_adapter.rb:407:in
`execute'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/connection_ada
pters/abstract/database_statements.rb:156:in
`insert_sql'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/connection_ada
pters/abstract/database_statements.rb:44:in
`insert_without_query_dirty'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/connection_ada
pters/abstract/query_cache.rb:19:in
`insert'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/connection_ada
pters/postgresql_adapter.rb:390:in
`insert'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/base.rb:2272:i
n
`create_without_callbacks'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/callbacks.rb:2
26:in
`create_without_timestamps'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/timestamp.rb:2
9:in
`create'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/base.rb:2238:i
n
`create_or_update_without_callbacks'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/callbacks.rb:2
13:in
`create_or_update'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/base.rb:1978:i
n
`save_without_validation!'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/validations.rb
:944:in
`save_without_transactions!'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/transactions.r
b:112:in
`save!'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/connection_ada
pters/abstract/database_statements.rb:66:in
`transaction'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/transactions.r
b:80:in
`transaction'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/transactions.r
b:100:in
`transaction'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/transactions.r
b:112:in
`save!'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/transactions.r
b:120:in
`rollback_active_record_state!'
    *
/usr/lib/ruby/gems/1.8/gems/activerecord-2.0.2-/lib/active_record/transactions.r
b:112:in
`save!'
    *
/usr/lib/ruby/gems/1.8/gems/rubycas-server-0.5.1/lib/casserver/cas.rb:40:in
`generate_service_ticket'
    *
/usr/lib/ruby/gems/1.8/gems/rubycas-server-0.5.1/lib/casserver/controllers.rb:15
1:in
`post'

I use RubyCAS 0.5.1, ActiveRecord 2.0.2 with PostgreSQL adapter (PostgreSQL
8.2.6) under Ubuntu Linux

I've fixed this problem by directly defining class method
descends_from_activerecord?:

  class ServiceTicket < Ticket
    set_table_name 'casserver_st'
    include Consumable

    def matches_service?(service)
      # We ignore the trailing slash in URLs, since 
      # "http://www.google.com/" and "http://www.google.com" are almost
      # certainly the same service.
      self.service.gsub(/\/$/, '') == service.gsub(/\/$/, '')
    end

    def self.descends_from_active_record?
      false
    end
  end

Original issue reported on code.google.com by me%html-...@gtempaccount.com on 21 Feb 2008 at 11:41

GoogleCodeExporter commented 8 years ago
Looks like single table inheritance is not working for some reason. I'm not 
sure if
setting descends_from_active_record? to false is the right way to fix this. 
I'll look
into it.

Original comment by matt.zuk...@gmail.com on 21 Feb 2008 at 5:25

GoogleCodeExporter commented 8 years ago
Okay try this:

1. Remove the self.descends_from-active_record? method you added.
2. Remove 'self.abstract_class = true' from the Ticket class definition.

See if that fixes it. I think it should (although I'm not entirely sure why :)

I've made the change in svn trunk so it should go out along with the next 
version.

Original comment by matt.zuk...@gmail.com on 21 Feb 2008 at 5:33

GoogleCodeExporter commented 8 years ago

Original comment by matt.zuk...@gmail.com on 27 Feb 2008 at 7:25