Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23160

Why hasattr gives KeyError?

$
0
0
chat = await Chat.objects.aget(chatid = chatid)if hasattr(chat, 'agent') and 'active' in chat.status:    await asyncio.sleep(5)

This code throws KeyError: 'agent'.

In Python 3 hasattr uses try-except underneath so it shoudn't be a problem if attribute doesn't exist. So what could be possible reasons?


Viewing all articles
Browse latest Browse all 23160

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>