check for required values
Happy to move this over to a discussion if necessary until we have a solid plan but based on #236, each object has required items that need to be defined on initialization.
This varies based on the object (not the object type).
Perhaps it would be good to create a validation step in there that checks for all of the required attributes.
To Implement
BaseObject would need a method validates that would be used to raise an AttributeError (?).
Since Page and Collection objects inherit from BaseObject then custom parsers can override it.
We can also apply the following validations.
Page - No validation
BlogPost - requires both date and content_path attributes.
I think in BaseObject.__init__ we can then pass
self.validates()
... # rest of code
@kjaymiller happy to take this up
Looking for a conversation in this before we decide. cc: @john0isaac
My biggest thought on this is do we need something that checks for things considering the build will fail without it.
I'm okay if we improve some of the error messages for some issues.
The worst is when you have a datetime issue with Blog and it gives can't order 'str' vs 'datetime'.
That could be better.
Still, usually validation issues only arise with custom content types so perhaps it would be better to documents steps on how to implement this.
That seems like a great idea.
It seems to me just like the behavior of __post_init__ in dataclasses
https://docs.python.org/3/library/dataclasses.html#dataclasses.post_init
I think if we can do something just like the post_init it would be great after initializing an instance of the object in the init the last step would be to run the post init based on the initialized object attributes to do whatever validation needed.
That seems like a great idea. It seems to me just like the behavior of
__post_init__indataclasseshttps://docs.python.org/3/library/dataclasses.html#dataclasses.post_initI think if we can do something just like the post_init it would be great after initializing an instance of the object in the init the last step would be to run the post init based on the initialized object attributes to do whatever validation needed.
My concern with this is that you now have an explicit thing that needs to be called.
old way
class CustomPage(Page):
def __init__(self):
super().__init__():
custom_code_logic()
self.validate()
new way
class CustomPage(Page):
def __init__(self):
super().__init__(): # this means validate runs here
custom_code_logic()
new way with validation last
class CustomPage(Page):
def __init__(self):
custom_code_logic() # You'd need to completely overwrite super().__init__()
self.validate()
After a brief conversation with @afimaamedufie, happy to take this if no one is looking at it
Happy to assign this to you! Do you have an opinion on how to approach this?
Also pinging @brass75 -
I know that you added the custom code logic directly to Blog and this issue predates you.