On 30/11/2010 11:10 PM, Jeremy Evans wrote:
On Nov 30, 12:01 pm, Gary Doades<[email protected]>  wrote:
Is is possible for Sequel to raise an error if a non-existent shard is
used in a call to .server or any other method that takes a :server option?

We've had some hard to track down problems because of Sequel falling
back to the :default server if given a server that does not exist. In
our case usually because it was mis spelled or wrong case. I.e someone
should have used :set123, but instead used :Set123. Having Sequel raise
an exception in such cases would make these problems mush easier to find
and also avoid potential database corruption or showing sensitive data
to the wrong user.

I don't mind if it is an option (on DB or call to Sequel.connect
perhaps), but it's hard to code around otherwise.
Makes sense to me: 
https://github.com/jeremyevans/sequel/commit/1c4e30c58e77f1af6cc7a9eb75e5a326492d959b

Hmm, I'm not sure this is working right, or, more likely, I'm using it wrong.

Simplified for testing:

defaultDB = "jdbc:sqlserver://localhost;databaseName=bev1234;user=sa;password=testing;"
servers = {}
servers[:bev1234] = {:uri => defaultDB}
DB = Sequel.connect(defaultDB, :servers => servers, :servers_hash => Hash.new{|h,v| raise Exception.new("Unknown server: #{v}")})

(so the :default server and the :bev1234 server should be the same?)

in irb results in:

=> #<Sequel::JDBC::Database: "jdbc:sqlserver://localhost;databaseName=bev1234;user=sa;password=testing;">

irb(main):008:0> DB[:client].first
Exception: Unknown server: read_only
        from (irb):7
irb(main):009:0> DB[:client].server(:default).first
Exception: Unknown server: read_only
        from (irb):7
irb(main):010:0> DB[:client].server(:bev1234).first
Exception: Unknown server: read_only
        from (irb):7
irb(main):011:0>

Normally the servers hash contains around 70 databases (shards) and then I initialise all my models. I'm guessing all the models try to use the default database, which they now can't and throw the above "Unknown server: ... " error. Even specifying the shard to one I know exists throws the exception.

I was hoping that not specifying any server (like for initialising the models) would still use :default, but any specific reference to a server that did not exist would raise an exception.

What am I doing wrong?

Thanks,
Gary.





--
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to