Coder Social home page Coder Social logo

Problem updating resource containing EmbeddedListField of Resource containing ReferenceField (and other fields) about django-tastypie-mongoengine HOT 15 CLOSED

wlanslovenija avatar wlanslovenija commented on August 15, 2024
Problem updating resource containing EmbeddedListField of Resource containing ReferenceField (and other fields)

from django-tastypie-mongoengine.

Comments (15)

mitar avatar mitar commented on August 15, 2024

Please create a pull request with failing test.

from django-tastypie-mongoengine.

m-vdb avatar m-vdb commented on August 15, 2024

yep, trying to find where it bugs with my best friend pdb, and if i succeed you'll have a pull request with a fix :D

from django-tastypie-mongoengine.

mitar avatar mitar commented on August 15, 2024

No no. You can also just make a pull request with a test which fails. And then I can also look.

from django-tastypie-mongoengine.

m-vdb avatar m-vdb commented on August 15, 2024

ok as you want, but since I need this to be fixed asap, I'll investigate too

from django-tastypie-mongoengine.

mitar avatar mitar commented on August 15, 2024

OK. So yes. You can create pull request with test. And then later on augment it with another commit with a fix. :-)

from django-tastypie-mongoengine.

m-vdb avatar m-vdb commented on August 15, 2024

done :)

btw, is there any support for DateTimeField ? (I can't see any document with a mongoengine.DateTimeField in documents.py)

from django-tastypie-mongoengine.

mitar avatar mitar commented on August 15, 2024

Yes, that one should be automatically available in resource.

from django-tastypie-mongoengine.

m-vdb avatar m-vdb commented on August 15, 2024

okay, I have something that fails, so I'll do another pull request.

For the first problem, I identified the cause :

in File tastypie_mongoengine.resources.py, line 475:

def obj_get(self, request=None, **kwargs):
    # MongoEngine exceptions are separate from Django exceptions, we combine them here
    try:
        return super(MongoEngineResource, self).obj_get(request, **kwargs)

In the returned function, tastypie does a query on the documents, and uses filter(**kwargs) on the queryset. And kwargs contains resource_uri, so that fails. A quick fix for me would be inserting kwargs.pop('resource_uri', None), but maybe this can be inserted upstream.

from django-tastypie-mongoengine.

mitar avatar mitar commented on August 15, 2024

You are doing invalid REST request.

from django-tastypie-mongoengine.

m-vdb avatar m-vdb commented on August 15, 2024

hum why is that ? could you explain a little more ?

from django-tastypie-mongoengine.

mitar avatar mitar commented on August 15, 2024

See the test I fixed.

from django-tastypie-mongoengine.

m-vdb avatar m-vdb commented on August 15, 2024

ok thanks for your help. Btw, my request was not that invalid. If I remove 'put' from the ExporterResource.allowed_method, the problem does not occur and everything goes well. Anyway, thanks for your help and your plugin 👍

from django-tastypie-mongoengine.

mitar avatar mitar commented on August 15, 2024

That's semi-normal. :-)

To be user friendly, you can specify referenced document by any unique combination of fields (like id). But on the other hand you can also in-place create a referenced document by specifying values. And then there is another user friendly thing: if there is some additional field in the request which is not in the document, it is ignored. Sometimes it can be not so intuitive how this interacts. :-) resource_uri is not a real field so when it tries to do a query it fails with error above. If you would remove resource_uri but leave other two fields, it should work. On the other hand, if it tries to create a new referenced document, it ignores resource_uri and just creates a new embedded document. So I am not so sure "problem does not occur" really happens. Probably it creates another referenced document, it does not reference the one you want.

This happens when you want to be user friendly and resolve ambiguities. :-)

from django-tastypie-mongoengine.

m-vdb avatar m-vdb commented on August 15, 2024

wow thanks for the explanation. I'll check that it does not create another document and that it does exactly what I want :-)

from django-tastypie-mongoengine.

mitar avatar mitar commented on August 15, 2024

OK, maybe that auto-creation does not really work always. :-)

from django-tastypie-mongoengine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.