agoragames / haigha

AMQP Python client
BSD 3-Clause "New" or "Revised" License
160 stars 41 forks source link

AttributeError: 'Channel' object has no attribute 'basic' when publish message #57

Open dizpers opened 10 years ago

dizpers commented 10 years ago

Hi! I write functional tests for my project, where I create RabbitMQ consumer using haigha =) There are both test producer and consumer in functional tests (started one by one). The producer randomly fails - opened channel closes randomly. When channel closed - no info is provided to close cb.

The only error I get is AttributeError: 'Channel' object has no attribute 'basic':

  File "/home/dizpers/work/myproject/.env/local/lib/python2.7/site-packages/haigha/channel.py", line 194, in publish
    self.basic.publish(*args, **kwargs)
AttributeError: 'Channel' object has no attribute 'basic'

What may cause this? How I can get more info from channel close callback? TIA!

PS The only cause I see for now is that consumer and producer started together.

dizpers commented 10 years ago

It seems like that resetting rabbitmq helps me. RabbitMQ logs contained following:

=ERROR REPORT==== 6-Jun-2014::01:26:46 ===
connection <0.3637.0>, channel 1 - soft error:
{amqp_error,precondition_failed,
            "cannot redeclare exchange 'test_exchange' in vhost '/' with different type, durable, intern...",
            'exchange.declare'}

=WARNING REPORT==== 6-Jun-2014::01:26:46 ===
closing AMQP connection <0.3637.0> (127.0.0.1:34669 -> 127.0.0.1:5672):
connection_closed_abruptly

but the most interesting thing - that exchange declaration code doesn't changed during multiple test running =)

awestendorf commented 10 years ago

Likely what happened is that the channel closed between when it was declared and when you attempted to publish, likely due to the protocol error you noted. Did you find a bug in your tests or is there a problem with exchange.declare?

dizpers commented 10 years ago

I think exchange.declare is fine. I did't get this error since I rewrite my tests.

simomo commented 10 years ago

Closing the channel ( channel.close() ) and then calling channel.basic may cause this error

awestendorf commented 10 years ago

Yeah I just proposed in #61 a change to closed channels that would make it much clearer to the user.