InterfaceError

180 views
Skip to first unread message

Thiago Galery

unread,
Jun 12, 2017, 8:37:05 AM6/12/17
to peewee-orm, Rishabh Shukla
Hi there, I'm using Peewee for a project and every now and then I'm getting a
peewee.InterfaceError: (0, '') Exception. I'm using PyMysql driver and am connecting to a Aws Aurora Mysql instance.
The stack trace of this function can be traced back to a very generic get_by_attr method inside a base class that my other models extend.
For example:

from peewee import Model

class BaseModel(Model):
    """
    This is an abstract class that provides common functionality for other models.
    """

    @classmethod
    def get_by_attr(cls, attr_name, attr_value):
        """
        Retrieve a model instance (row) by an attribute name and value.

        :param attr_name: str: the name of the attribute, e.g. "url"
        :param attr_value: any: any value for the attribute name
        :return: peewee.model.ModelInstance
        """
        try:
            with db.atomic():
                attr = getattr(cls, attr_name)
                return cls.get(attr == attr_value)
        except Exception as ex:
            logger.warning("Model %s does not have instance with %s == %s. %s", cls.__name__, attr_name,
                           attr_value, ex)



If a model named Content which extends from BaseModel and has an unique attribute called 'url' I could retrieve the model instance by running `Content.get_by_attr("url", url)` (where url is a variable which points to some url string).

Things were working fine when using this on sqlite, but when I switched to myslq, some errors started to creep up. Am I doing something wrong here ?

Also, I'm using Peewee with the hug (an extension of Falcon) framework. At the moment, we are exposing CRUD operation for some of our models, but this means we would have to re-write the whole logic inside the Hug routes. Do people know some MVC component that can be added as some sort of Middleware between the Hug (or falcon) routes and the Pewee models ?

Any help would be appreciated,
all the best,
Thiago

Charles Leifer

unread,
Jun 12, 2017, 9:43:47 AM6/12/17
to peewe...@googlegroups.com
Your code looks fine to me, I suspect the issue is coming from the db driver or some issue connecting to aws. If you could trace the error to the relevant code in pymysql that'd obviously be helpful, and possibly illuminate what is actually triggering the exception.

No clue on the MVC stuff, maybe someone else reading the list can help.

--
You received this message because you are subscribed to the Google Groups "peewee-orm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to peewee-orm+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages