chicks / sugarcrm

A ruby based REST Client for SugarCRM
MIT License
90 stars 64 forks source link

Invalid Session problem #84

Closed wizardone closed 12 years ago

wizardone commented 12 years ago

I've been brainstorming this for quite a while now. I`m importing information from csv files into SugarCrm and at some point i get an "invalid session" thrown. I checked the the following code: rescue SugarCRM::InvalidSession => error @errors << error old_session = @sugar_session_id.dup login!

Update the session id in the request that we want to retry.

  json.gsub!(old_session, @sugar_session_id)
  send!(method, json, max_retry.pred)

and after some debugging i found out that the session was not updated( old_session == @sugar_session_id after the login! method which should update the session_id). I tried to mess with the code a little bit, tried to logout, then login again but nothing seems to help. Any ideas?

chicks commented 12 years ago

Hrm... Can you share the code you are using to load the data from the CSV? I do this pretty regularly and I haven't run into this (yet).

wizardone commented 12 years ago

Sure, but first i have to clarify that the problem does not occur during the initial insert of data. The data has already been inserted, but when i try to create the corresponding Security Groups(to group the various entries, which i`ve inserted) it happens.

if @isos
        @logger.info("Puting ISOs into ISO groups")
        role = @sugarcrm_namespace::ACLRole.find_by_name("isos")
        @isos.each do |iso|
          unless find_sugarcrm_object('security_group','name', iso.name)
            sg     = @sugarcrm_namespace::SecurityGroup.new(:name => iso.name)
            @logger.info("Security group for iso #{iso.name} not found, created one called #{sg.name}")
            user   = @sugarcrm_namespace::User.find_by_last_name(iso.name)
            @logger.info("Puting Iso #{iso.name} and User #{user.last_name} in Security Group #{sg.name}")
            sg.save!
            iso.associate! sg
            user.associate! sg
            role.associate! sg
          end
        end
      end
- @isos - the custom object in SugarCRM

Now this method works completely fine for the first several records, than at some point i receive the "name"=>"Invalid Session ID" response in my session. I just don`t know what to do anymore. Also tried to to set the max_retriesto a bigger number in case there was some connection problem, but it was no good. :( Thanks for the feedback, i hope we can fix this somehow.

chicks commented 12 years ago

Can you expand on your usage of @sugarcrm_namespace? Why aren't you just using SugarCRM::ACLRole.find_by_name("isos")? Are you connecting to multiple SugarCRM instances?

wizardone commented 12 years ago

@sugarcrm_namespace holds the connection to my instance of SugarCRM. And no, i`m using a single connection.

chicks commented 12 years ago

The connection is a singleton in the SugarCRM namespace, so you don't need to assign the result of SugarCRM.connect to a variable. Can you try replacing @sugarcrm_namespace with SugarCRM in your code?

wizardone commented 12 years ago

Hi, i've been able to fix this bug. As it seems the problem were the quotes. As i told you i was importing data from csv files and i saw that Invalid Session was returned when i was inserting a particular record. It had double quotes in it's name, so after removing them everything ran smoothly(this also happend to another record so i can absolutely verify that this was the issue). How this could corrupt the whole session - i don't know, but thanks for the assistance. P.S. I didn`t replace the @sugarcrm_namespace prior to fixing this, but i will now, thanks.

chicks commented 12 years ago

Ahhhhh! I've seen that before - sorry I didn't suggest it earlier. We try to escape characters before we send them over, but there's a bug in SugarCRM which prevents us from handling all cases properly.

wizardone commented 11 years ago

Sorry to bother with this problem again, but i'm receiving this error again in a completely different case and i just don`t know how to debug anymore, since it is as generic error as it gets. No quotes this time. Script working fine on my local MacOS, but when deployed on Ubuntu 12.04 everything fails. I am again importing information from csv files, but no matter what i import i will always get this error. Tried to set the encoding of the csv files to utf-8, but nothing.

dobromirpeev commented 7 years ago

I got the same error, but found when it has been appear. When in string for save/update object exist this one &lt; and &rt; . So my hot fix is string.gsub!(/\&lt;/, '') and string.gsub!(/\&rt;/, '')