-
Notifications
You must be signed in to change notification settings - Fork 981
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
Add new API Version to validate when setting fields not defined in the schema #4894
Changes from 3 commits
02c4328
ce27a4d
648dedd
7e132f0
af14d42
2289fea
d25c639
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -379,6 +379,20 @@ impl InputSchema { | |
.map(|fields| fields.contains(&field)) | ||
.unwrap_or(false) | ||
} | ||
|
||
pub fn has_field_with_name(&self, entity_type: &EntityType, field: &str) -> bool { | ||
let field = self.inner.pool.lookup(field); | ||
|
||
match field { | ||
Some(field) => self | ||
.inner | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just call |
||
.field_names | ||
.get(entity_type) | ||
.map(|fields| fields.contains(&field)) | ||
.unwrap_or(false), | ||
None => false, | ||
} | ||
} | ||
} | ||
|
||
/// Create a new pool that contains the names of all the types defined | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,9 +199,18 @@ impl<C: Blockchain> HostExports<C> { | |
} | ||
} | ||
|
||
// Filter out any key-value pairs from 'data' where | ||
// the key (field name) is not defined in the schema for the given entity type. | ||
let filtered_entity_data = data.into_iter().filter(|(k, _)| { | ||
state | ||
.entity_cache | ||
.schema | ||
.has_field_with_name(&key.entity_type, k.as_str()) | ||
}); | ||
|
||
let entity = state | ||
.entity_cache | ||
.make_entity(data.into_iter().map(|(key, value)| (key, value))) | ||
.make_entity(filtered_entity_data.map(|(key, value)| (key, value))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That |
||
.map_err(|e| HostExportError::Deterministic(anyhow!(e)))?; | ||
|
||
let poi_section = stopwatch.start_section("host_export_store_set__proof_of_indexing"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small typo: s/doesnt/don't/