Question: How can I pass the context in a nested field of a structured dict?
See original GitHub issueI noticed that if you use a nested field for values in a structured Dict, the context is not automatically given to the nested schema. Is there a way to pass it the context?
Example:
class Inner(Schema):
foo = fields.String()
@validates('foo')
def validate_foo(self, value):
if 'foo_context' not in self.context:
raise ValidationError('no context!')
class Outer(Schema):
bar = fields.Dict(values=fields.Nested(Inner))
# gives no error:
Inner(context={'foo_context': 'foo'}).load({'foo': 'some foo'})
# gives 'no context!' error:
Outer(context={'foo_context': 'foo'}).load({'bar': { 'key': {'foo': 'some foo'}}})
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
python - How do I use nested lists properly in that context
I need to create a memory game in Python. I need to print a 5x4 (4 rows, 5 elements in a line) field...
Read more >collections — Container datatypes — Python 3.11.1 ...
This module implements specialized container datatypes providing alternatives to Python's general purpose built-in containers, dict , list , set , and tuple ....
Read more >Sorting a Python Dictionary: Values, Keys, and More
In this tutorial, you'll get the lowdown on sorting Python dictionaries. By the end, you'll be able to sort by key, value, or...
Read more >Translating dictionary keys in complex nested Python structures
Put simply: given a structure (e.g. nested dictionaries) and a mapping of old dictionary keys to new ones, produce a new structure that...
Read more >Specify nested and repeated columns in table schemas
To create a column with repeated data, set the mode of the column to REPEATED in the schema. A repeated field can be...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Dict
needs to copy the_add_to_schema
logic fromList
to link the “container” to the parent.It looks like
List
works as expected. The following test passes on2.x-line
:And I verified that the test fails if
outer.context['foo_context'] = 'foo'
is removed.