milesrichardson / ParsePy

A relatively up-to-date fork of ParsePy, the Python wrapper for the Parse.com API. Originally maintained by @dgrtwo
MIT License
516 stars 184 forks source link

BUG: Relation is not Valid -- Adding Relations screws up with being able to save (and therefore edit) objects #153

Closed SovcikJoe closed 8 years ago

SovcikJoe commented 8 years ago

So the previous issue here is still happening.

What is the problem? When adding a relation to a Class, the save() stops working and an error gets raised

error 111 "This is not a valid relation"

How to reproduce This was reproduced locally as well as on a hosted ParseServer by back4app. It is reporducable just by following the instructions at the intro. Instantly as the relation is added, the object can't use .save() method.

This to me seems like a huge problem.

Maybe @johnkawakami could chip in as he introduced Relation support.

Here's a stacktrace:

HTTPError                                 Traceback (most recent call last)
/home/theshade/.virtualenvs/ParseBabynames/lib/python3.5/site-packages/parse_rest/connection.py in execute(cls, u
ri, http_verb, extra_headers, batch, _body, **kw)
    133         try:
--> 134             response = urlopen(request, timeout=CONNECTION_TIMEOUT)

    135         except HTTPError as e:

home/theshade/anaconda3/lib/python3.5/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault
, context)
    162         opener = _opener
--> 163     return opener.open(url, data, timeout)
    164

/home/theshade/anaconda3/lib/python3.5/urllib/request.py in open(self, fullurl, data, timeout)
    471             meth = getattr(processor, meth_name)
--> 472             response = meth(req, response)
    473

/home/theshade/anaconda3/lib/python3.5/urllib/request.py in http_response(self, request, response)

   581             response = self.parent.error(
--> 582                 'http', request, response, code, msg, hdrs)
    583

/home/theshade/anaconda3/lib/python3.5/urllib/request.py in error(self, proto, *args)
    509             args = (dict, 'default', 'http_error_default') + orig_args
--> 510             return self._call_chain(*args)
    511

/home/theshade/anaconda3/lib/python3.5/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
    443             func = getattr(handler, meth_name)

--> 444             result = func(*args)
    445             if result is not None:

/home/theshade/anaconda3/lib/python3.5/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
    589     def http_error_default(self, req, fp, code, msg, hdrs):
--> 590         raise HTTPError(req.full_url, code, msg, hdrs, fp)
    591

HTTPError: HTTP Error 400: Bad Request

During handling of the above exception, another exception occurred:

ResourceRequestBadRequest                 Traceback (most recent call last)

<ipython-input-35-993ea11b1e77> in <module>()
----> 1 game.save()

/home/theshade/.virtualenvs/ParseBabynames/lib/python3.5/site-packages/parse_rest/datatypes.py in save(self, batc
h)
    461     def save(self, batch=False):
    462         if self.objectId:
--> 463             return self._update(batch=batch)
    464         else:
    465             return self._create(batch=batch)

/home/theshade/.virtualenvs/ParseBabynames/lib/python3.5/site-packages/parse_rest/datatypes.py in _update(self, b
atch)

    480     def _update(self, batch=False):
--> 481         response = self.__class__.PUT(self._absolute_url, batch=batch, **self._to_native())
    482
    483         def call_back(response_dict):

/home/theshade/.virtualenvs/ParseBabynames/lib/python3.5/site-packages/parse_rest/connection.py in PUT(cls, uri,
**kw)
    154     @classmethod
    155     def PUT(cls, uri, **kw):
--> 156         return cls.execute(uri, 'PUT', **kw)
    157

    158     @classmethod

/home/theshade/.virtualenvs/ParseBabynames/lib/python3.5/site-packages/parse_rest/connection.py in execute(cls, u
ri, http_verb, extra_headers, batch, _body, **kw)
    140                 404: core.ResourceRequestNotFound
    141                 }.get(e.code, core.ParseError)
--> 142             raise exc(e.read())
    143
    144         return json.loads(response.read().decode('utf-8'))

ResourceRequestBadRequest: b'{"code":111,"error":"This is not a valid Relation"}'

Maybe this might help

milesrichardson commented 8 years ago

@SovcikJoe this should be fixed in commit 5a86ba0

@johnkawakami It would be nice if you could take a look at the changes in the commit.

Seems like the main problem is that you had commented out # self.__dict__[key] = '' in ParseResource but not ParseUser

SovcikJoe commented 8 years ago

That seems to solve the issue, thank you @milesrichardson