KeyError with nested patternProperties
See original GitHub issueWhen an object using patternProperties is further down the tree than another patternProperties field you get a KeyError.
Example schema:-
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"patternProperties": {
"^foo:": {
"type": "object",
"properties": {
"baz": {
"type": "object",
"patternProperties": {
"^b": {
"type": "object"
}
}
},
"bit": {
"type": "object"
}
},
"required": [
"baz",
"bit"
]
}
}
}
Example document to validate against it :-
{
"foo:bar": {
"baz": {
"bat": {
}
},
"bit": {
}
}
}
This results in :-
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 38, in validate
KeyError: 'bit'
The following schema where the second patternProperties is replaced with a regular properties validates correctly:-
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"patternProperties": {
"^foo:": {
"type": "object",
"properties": {
"baz": {
"type": "object",
"properties": {
"bat": {
"type": "object"
}
}
},
"bit": {
"type": "object"
}
},
"required": [
"baz",
"bit"
]
}
}
}
The following where the first patterProperties is replaced also validates correctly:-
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"foo:bar": {
"type": "object",
"properties": {
"baz": {
"type": "object",
"patternProperties": {
"^b": {
"type": "object"
}
}
},
"bit": {
"type": "object"
}
},
"required": [
"baz",
"bit"
]
}
}
}
Issue Analytics
- State:
- Created 5 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Key error when accessing a nested dictionary - Stack Overflow
I have the following list of nested dictionaries: raw_data = [ { "type": "message", "subtype": "bot_message", "text": "This content can't be ...
Read more >bug in Nested field processing None value · Issue #920 - GitHub
It looks like there are 2 other places in this file that use the try except KeyError pass else pattern that would break...
Read more >How do I handle key errors on nested dictionaries? - Reddit
The problem is, the keys that I'm extracting from the xml file need NOT always exist. There is a standard pattern for these...
Read more >Python | Safe access nested dictionary keys - GeeksforGeeks
Sometimes, while working with Python we can have a problem in which we need to get the 2nd degree key of dictionary i.e...
Read more >What is KeyError in Python? Dictionary and Handling Them
Now let us see what a key error is. KeyError in Python is raised when you attempt to access a key that is...
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 Free
Top 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

Thanks @FrederikP, you found the bug. 😃 The same problem was on more places. It’s fixed in master. I plan to do more stuff tomorrow, do you want to release it today or can you wait till tomorrow, @j616?
I can wait until tomorrow. For now it’s useful to know I don’t have to find a work around and to know I’m not doing anything silly on my end! Thanks.