Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properties to_dict() overrides type when use same InnerDoc for Object and Nested fields #1256

Closed
bukhem opened this issue Oct 21, 2019 · 2 comments
Labels
Category: Bug Something isn't right

Comments

@bukhem
Copy link

bukhem commented Oct 21, 2019

Hi there!
Thanks for your work.

I have the following code

from elasticsearch_dsl import InnerDoc, DocType, Object, Nested

class DummyInnerDoc(InnerDoc): pass

class TestDocument(DocType):
    spam = Object(DummyInnerDoc)
    eggs = Nested(DummyInnerDoc)

TestDocument._doc_type.mapping.to_dict()

and got mapping with type nested for both fields:

{'properties': {'spam': {'type': 'nested'}, 'eggs': {'type': 'nested'}}}

but expected that mapping should be:

{'properties': {'spam': {'type': 'object'}, 'eggs': {'type': 'nested'}}}.

If I switch fields order to (nested first and object second):

class TestDocument(DocType):
    eggs = Nested(DummyInnerDoc) 
    spam = Object(DummyInnerDoc)   

I got type object for both fields.

Is it an expected behavior to keep same mapping for concrete InnerDoc? If so, what do you recommend to me when I need to have same InnerDoc for Object and Nested fields in document?

Of course, I can declare second class like class NestedDummyInnerDoc(DummyInnerDoc): pass and use it for nested fields, but is it right way to solve my problem?

Thanks for help.

@l1nd3r0th
Copy link
Contributor

I got bitten by the same bug a few months ago. I submitted a patch:
#1255

@miguelgrinberg
Copy link
Collaborator

Closing, since this has been addressed in #1255

@miguelgrinberg miguelgrinberg added the Category: Bug Something isn't right label Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Bug Something isn't right
Projects
None yet
Development

No branches or pull requests

3 participants