-
Notifications
You must be signed in to change notification settings - Fork 73
docs: internals: Add system fields #801
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
base: master
Are you sure you want to change the base?
docs: internals: Add system fields #801
Conversation
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.
LGTM! only one thing I'd change
|
||
## Architecture and core concepts | ||
|
||
### The Foundation |
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.
I would remove this heading as the following information doesn't need it
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.
+1
record = MyRecord({'metadata': {'title': 'hello world'}}) | ||
print(record.title) # "HELLO WORLD" | ||
record.title = "New Title" | ||
print(record['metadata']['title']) # "new title" |
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.
nice example!
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.
Lots of little comments, but honestly this is such useful documentation. System fields are by far the part of the code base that I've found the most unpenetrable and having documentation that lays it all out is wonderful. Thanks for all that.
@@ -1,47 +1,701 @@ | |||
# Build a system field | |||
# System Fields |
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.
Probably best to go one of two ways completely:
# System Fields | |
# System fields |
(I slightly prefer this one because it allows us to talk about the concept separate from the Python class)
or
# System Fields | |
# SystemFields |
. And then stick with that throughtout the text and filenaming. Singular or plural too should be settled on.
|
||
Clear API, produce clear service flow. Abstract indexing. | ||
Data wrangling. Data integrity. | ||
SystemFields is a powerful abstraction layer in InvenioRDM that provides managed access to record data through Python descriptors. It bridges the gap between the raw JSON dictionary structure of records and object-oriented Python interfaces, enabling sophisticated data management, validation, and integration with related objects. |
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.
so .e.g.,
SystemFields is a powerful abstraction layer in InvenioRDM that provides managed access to record data through Python descriptors. It bridges the gap between the raw JSON dictionary structure of records and object-oriented Python interfaces, enabling sophisticated data management, validation, and integration with related objects. | |
System fields are a powerful abstraction layer in InvenioRDM that provide managed access to record data through Python descriptors. They bridge the gap between the raw JSON dictionary structure of records and object-oriented Python interfaces, enabling sophisticated data management, validation, and integration with related objects. |
|
||
## Directory structure | ||
At its core, SystemFields transforms simple attribute access (`record.title`) into complex operations that can involve: |
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.
At its core, SystemFields transforms simple attribute access (`record.title`) into complex operations that can involve: | |
At its core, System fields transform simple attribute access (`record.title`) into complex operations that can involve: |
# When you access record.title, SystemField.__get__ is called | ||
# When you set record.title = "New Title", SystemField.__set__ is called |
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.
(to prefer active voice and relate it to the code on display)
# When you access record.title, SystemField.__get__ is called | |
# When you set record.title = "New Title", SystemField.__set__ is called | |
# record.title calls ConstantField.__get__ | |
# record.title = "New Title" calls ConstantField.__set__ |
|
||
## Architecture and core concepts | ||
|
||
### The Foundation |
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.
+1
class TimestampField(SystemField): | ||
"""A field that tracks creation and modification times.""" |
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.
class TimestampField(SystemField): | |
"""A field that tracks creation and modification times.""" | |
from invenio_records.api import Record | |
from invenio_records.systemfields import SystemField, SystemFieldsMixin | |
class TimestampField(SystemField): | |
"""A field that tracks creation and modification times.""" |
|
||
## Relations | ||
|
||
Relations are specialized SystemFields that manage connections between records and external entities (other records, database models, APIs, etc.). |
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.
Relations are specialized SystemFields that manage connections between records and external entities (other records, database models, APIs, etc.). | |
Relations are specialized SystemFields that manage connections between records and other entities (other records, database models, APIs, etc.). |
- **RelationsField**: The main system field that manages multiple relations | ||
- **Relation Classes**: Define how to resolve and validate specific relation types | ||
- **Result Classes**: Handle the returned values when accessing relations | ||
- **Mapping Class**: Provides the interface for managing relations on a record |
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.
Can we make explicit the relationship between these classes and the concrete code below or concrete code in general? For example, RelationsField is invenio_records.systemfields.relations.RelationsField
, a Relation class can be PKRelation
and so on...
Mapping Class
-> Mapping Classes
|
||
## Idempotence and Data Consistency | ||
|
||
SystemFields are designed to be idempotent - running the same operation multiple times should produce the same result: |
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.
They are meant to be, but there is no enforcement - it's up to the developer. So I guess it's more a matter of advising developers to respect that principle 😁 : . Not sure if any example would help for that. Perhaps a note block instead? And perhaps move it to the "Best practices" section?
|
||
## Caching | ||
By following these patterns and best practices, you can create robust, maintainable SystemFields that enhance your InvenioRDM instance's capabilities while maintaining clean, readable code. |
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.
This section is for maintainers and core developers rather than instance operators:
- we can either skip the Conclusion section completely (not really an essay or an AI answer right? haha)
- Or
By following these patterns and best practices, you can create robust, maintainable SystemFields that enhance your InvenioRDM instance's capabilities while maintaining clean, readable code. | |
By following these patterns and best practices, you can create robust, maintainable System fields that enhance InvenioRDM's capabilities while maintaining clean, readable code. |
No description provided.