question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use mixins in schema declarations

See original GitHub issue

Hello. Is there any way to use mixins with umongo Document class? I have following structures:

class A(EmbeddedDocument):
  field1 = StringField()
  field2 = StringField()
  ...
  field99 = StringField()


class B(Document):
  field1 = StringField()
  field2 = StringField()
  ...
  field99 = StringField()
  items = ListField(EmbeddedDocumentField(A))

I want to put all of my fields to another class and use it as mixin for A and B. Is it possible in umongo?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
lafrechcommented, May 3, 2020

@gerasim13 #267 should fix this.

There’an an issue with your implementation: the mixin overrides the doc class fields in case of name collision, while expected behaviour would be the doc class overriding the mixin. This is why I use setdefault in #267.

0reactions
lafrechcommented, May 7, 2019

Right. I just fell into this myself.

I think this could be fixed by modifying _collect_schema_attrs in builder.py. Make it recursive, and change parameter to template instead of template.__dict__.

I don’t have time for this right now but I’d be happy to merge a PR implementing it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

complexType "mixin" | XML Schema Documentation
The fully qualified classname of the mixin class that defines the annotations to overlay on the object. This must be an abstract class...
Read more >
Mixin and Custom Base Classes
In addition to using a pure mixin, most of the techniques in this section ... The most basic way to specify a column...
Read more >
Client schema | Creatio Academy
When naming mixins, use an -able suffix in the schema name. For example, name a mixin that enables serializing in the components Serializable...
Read more >
Is there a way to define certain parts of my JSON schema as ...
One way you can extend the core schema is to use allOf to essentially mixin the core schema with your new fields. {...
Read more >
Mixins API Endpoint | Adobe Experience Platform
The /mixins endpoint in the Schema Registry API allows you to programmatically manage XDM mixins within your experience application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found