Archived

This forum has been archived. Please start a new discussion on GitHub.

Python UnexpectedObjectException has incorrect details

In my python code, I have written an Ice.ObjectFactory subclass to create instances of an ICE class I am using. I stuffed up and returned the wrong type, and got this exception:

Ice.UnexpectedObjectException: exception ::Ice::UnexpectedObjectException
{
reason = unmarshaled object is not an instance of ::Basket::Entities::Entity
GroupData
type = ::Basket::Entities::EntityGroupData
expectedType = ::Basket::Entities::EntityGroupData
}

Obviously I need to fix my class factory :-)

However, I also suspect that the `type' parameter of the Ice.UnexpectedObjectException is wrong. Shouldn't it be "::Basket::Entities::BaseEntityData" (ie. the type of the object I actually returned from my class factory) rather than "::Basket::Entities::EntityGroupData" (ie. the type of the object I should have returned)? Or is there some other subtlety here that I am not aware of?

Cheers,
garyD!

Comments

  • mes
    mes California
    Hi Gary,

    You're right, the type member should show the actual type of the object. Unfortunately, I can't reproduce this behavior. Do you have a small test case? Also, can you describe your environment (OS, Python version, Ice version, etc.)?

    Thanks,
    Mark
  • Sorry - environment details are:
    * Windows XP Pro SP3
    * Python v2.6.1
    * ICE v3.3.1

    The situation is that I have (ICE) class B extends class A, and class C extends class A. My factory returned an instance of B instead of C.

    I will try to work up a simple example for you.

    cheers,
    gary
  • mes
    mes California
    Thanks Gary, but I don't think I'll need a test case after all.

    If your factory incorrectly returns an object that is not of the expected type, it would explain the bogus type member in the exception. The Ice run time assumes that when it asks a factory for an object of a certain type, the factory will actually return an instance of that type. :)

    Regards,
    Mark
  • Okay, I just had a look at your source code, and I see what you mean. When UnexpectedObjectException gets thrown (in IcePy::ReadObjectCallback::invoke) we have to use the ID from the reader, rather than trying to infer it from an arbitrary python object (that may not have an ID).

    So an enhancement might be to check the return value from a factory and provide a more specific error message, but that's probably not very important (I know I am not motivated to go and write it :-).

    Thanks,
    gary