Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
Notebook_Processor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maurice Herné
Notebook_Processor
Commits
8ab2f4cb
Commit
8ab2f4cb
authored
7 months ago
by
Maurice Herné
Browse files
Options
Downloads
Patches
Plain Diff
Better way to do the attachments fix
parent
7e3ad3e2
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Notebook_Processor/notebook_models/notebook_cell_model.py
+26
-2
26 additions, 2 deletions
...Notebook_Processor/notebook_models/notebook_cell_model.py
with
26 additions
and
2 deletions
src/Notebook_Processor/notebook_models/notebook_cell_model.py
+
26
−
2
View file @
8ab2f4cb
...
...
@@ -6,6 +6,7 @@ from typing import (
Annotated
,
Union
,
Literal
,
Optional
,
Any
,
)
from
uuid
import
uuid4
...
...
@@ -17,6 +18,7 @@ from pydantic import (
field_validator
,
ValidationInfo
,
ConfigDict
,
model_serializer
,
)
from
..configuration
import
(
...
...
@@ -78,13 +80,35 @@ class BaseNotebookCellModel(BaseModel):
raise
PydanticUseDefault
()
return
value
@model_serializer
def
drop_optional_none_fields
(
self
):
"""
Drops optional fields that are None.
We should look for a more dynamic solution to this.
Currently those fields need to be hardcoded because there is no way to specifically
detect fields that are annotated as Optional because the matching only returns true
if you get it exactly (Optional != Optional[dict]).
:return: The model with the optional fields that are None removed.
"""
optional_fields
=
[
"
attachments
"
,
]
drop
=
{
key
for
key
,
value
in
self
.
__dict__
.
items
()
if
value
is
None
and
key
in
optional_fields
}
return
{
key
:
value
for
key
,
value
in
self
.
__dict__
.
items
()
if
key
not
in
drop
}
class
NotebookMarkdownCellModel
(
BaseNotebookCellModel
):
"""
"
Notebook markdown cell.
"
"""
cell_type
:
Literal
[
"
markdown
"
]
attachments
:
dict
=
Field
(
default
=
{}
,
description
=
"
Media attachments (e.g. inline images), stored as mimebundle keyed by filename.
"
)
attachments
:
Optional
[
dict
]
=
Field
(
default
=
None
,
description
=
"
Media attachments (e.g. inline images), stored as mimebundle keyed by filename.
"
)
class
NotebookCodeCellModel
(
BaseNotebookCellModel
):
...
...
@@ -101,7 +125,7 @@ class NotebookRawCellModel(BaseNotebookCellModel):
"
Notebook raw nbconvert cell.
"
"""
cell_type
:
Literal
[
"
raw
"
]
attachments
:
dict
=
Field
(
default
=
{}
,
description
=
"
Media attachments (e.g. inline images), stored as mimebundle keyed by filename.
"
)
attachments
:
Optional
[
dict
]
=
Field
(
default
=
None
,
description
=
"
Media attachments (e.g. inline images), stored as mimebundle keyed by filename.
"
)
NotebookCellAnnotation
=
Annotated
[
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment