Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sakshamarora1
Copy link
Contributor

No description provided.

Copy link
Contributor

@carlinmack carlinmack left a 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
Copy link
Contributor

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Comment on lines +109 to +112
record = MyRecord({'metadata': {'title': 'hello world'}})
print(record.title) # "HELLO WORLD"
record.title = "New Title"
print(record['metadata']['title']) # "new title"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice example!

Copy link
Collaborator

@fenekku fenekku left a 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
Copy link
Collaborator

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:

Suggested change
# System Fields
# System fields

(I slightly prefer this one because it allows us to talk about the concept separate from the Python class)

or

Suggested change
# 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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so .e.g.,

Suggested change
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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:

Comment on lines +25 to +26
# When you access record.title, SystemField.__get__ is called
# When you set record.title = "New Title", SystemField.__set__ is called
Copy link
Collaborator

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)

Suggested change
# 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Comment on lines +118 to +119
class TimestampField(SystemField):
"""A field that tracks creation and modification times."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.).

Comment on lines +169 to +172
- **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
Copy link
Collaborator

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:
Copy link
Collaborator

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.
Copy link
Collaborator

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
Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In review 🔍
Development

Successfully merging this pull request may close these issues.

3 participants