pythonormponyponyorm

ValueError: Attribute Users.request is required


I need help again. Can anybody tell my why I get this error? I use Flask and pony orm and python 3.4. I have few files.

users.py

from app import models
from pony.orm import *

class UsersAPI:
    @staticmethod
    @db_session
    def is_registered(e_mail):
        """
        This method for checking registered user or not
        :param e_mail:
        :return:
        """

        user = select(o for o in models.Users if o.email == e_mail)[:]
        print(user)

UsersAPI.is_registered("evgenusov96@yandex.ru")

File models.py

from pony.orm import *
import config

db = Database()

class Users(db.Entity):
    id = PrimaryKey(int, auto=True)
    email = Required(str, 100)
    password = Required(str, 32)
    name = Required(str, 15)
    surname = Required(str, 20)
    city = Required(City, nullable=True)
    sex = Required(int)
    request = Required(str, 250, nullable=True)
    hobby = Required(str, 250, nullable=True)
    about = Required(str, 250, nullable=True)
    status_message = Required(str, 100, nullable=True)
    user1 = Set("Friends", reverse="user1")
    user2 = Set("Friends", reverse="user2")
    author = Set("Messages", reverse="author")
    addressee = Set("Messages", reverse="addressee")

This error I got:

    C:\Python34\python.exe C:/Users/Евгений/PycharmProjects/langunet/run.py
Traceback (most recent call last):
  File "C:/Users/Евгений/PycharmProjects/langunet/run.py", line 2, in <module>
    from app import app
  File "C:\Users\Евгений\PycharmProjects\langunet\app\__init__.py", line 4, in <module>
    from app import routes
  File "C:\Users\Евгений\PycharmProjects\langunet\app\routes.py", line 2, in <module>
    from app.users import *
  File "C:\Users\Евгений\PycharmProjects\langunet\app\users.py", line 21, in <module>
    UsersAPI.is_registered("evgenusov96@yandex.ru")
  File "<string>", line 2, in is_registered
  File "C:\Python34\lib\site-packages\pony\orm\core.py", line 347, in new_func
    try: return func(*args, **kwargs)
  File "C:\Users\Евгений\PycharmProjects\langunet\app\users.py", line 18, in is_registered
    user = get(o for o in models.Users if o.email == e_mail)
  File "<string>", line 2, in get
  File "C:\Python34\lib\site-packages\pony\utils.py", line 88, in cut_traceback
    return func(*args, **kwargs)
  File "C:\Python34\lib\site-packages\pony\orm\core.py", line 4260, in get
    return make_query(args, frame_depth=3).get()
  File "<string>", line 2, in get
  File "C:\Python34\lib\site-packages\pony\utils.py", line 88, in cut_traceback
    return func(*args, **kwargs)
  File "C:\Python34\lib\site-packages\pony\orm\core.py", line 4531, in get
    objects = query[:2]
  File "<string>", line 2, in __getitem__
  File "C:\Python34\lib\site-packages\pony\utils.py", line 88, in cut_traceback
    return func(*args, **kwargs)
  File "C:\Python34\lib\site-packages\pony\orm\core.py", line 4721, in __getitem__
    return query._fetch(range=(start, stop))
  File "C:\Python34\lib\site-packages\pony\orm\core.py", line 4426, in _fetch
    used_attrs=translator.get_used_attrs())
  File "C:\Python34\lib\site-packages\pony\orm\core.py", line 3228, in _fetch_objects
    real_entity_subclass, pkval, avdict = entity._parse_row_(row, attr_offsets)
  File "C:\Python34\lib\site-packages\pony\orm\core.py", line 3258, in _parse_row_
    avdict[attr] = attr.parse_value(row, offsets)
  File "C:\Python34\lib\site-packages\pony\orm\core.py", line 1329, in parse_value
    val = attr.validate(row[offset], None, attr.entity, from_db=True)
  File "C:\Python34\lib\site-packages\pony\orm\core.py", line 1611, in validate
    if obj is None: throw(ValueError, 'Attribute %s is required' % attr)
  File "C:\Python34\lib\site-packages\pony\utils.py", line 126, in throw
    raise exc
ValueError: Attribute Users.request is required

How this may to fix? Thank you!


Solution

  • This error can happen if you defined User.request attribute as Required, but in the table the corresponding column is actually optional (that is, nullable). During loading of an object, Pony checks if the object's internal state is consistent. Since the value of a required attribute is missed, Pony generates an exception.

    I think that we need to improve Pony behavior in one of two ways here: