render-engine icon indicating copy to clipboard operation
render-engine copied to clipboard

check for required values

Open kjaymiller opened this issue 1 year ago • 9 comments

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.

kjaymiller avatar Sep 04 '24 19:09 kjaymiller

I think in BaseObject.__init__ we can then pass

self.validates()
... # rest of code  

kjaymiller avatar Sep 04 '24 19:09 kjaymiller

@kjaymiller happy to take this up

JohananOppongAmoateng avatar Oct 12 '24 16:10 JohananOppongAmoateng

Looking for a conversation in this before we decide. cc: @john0isaac

kjaymiller avatar Oct 14 '24 14:10 kjaymiller

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.

kjaymiller avatar Oct 14 '24 15:10 kjaymiller

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.

john0isaac avatar Oct 19 '24 18:10 john0isaac

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.

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()

kjaymiller avatar Oct 29 '24 08:10 kjaymiller

After a brief conversation with @afimaamedufie, happy to take this if no one is looking at it

Kemosalamy avatar Sep 22 '25 10:09 Kemosalamy

Happy to assign this to you! Do you have an opinion on how to approach this?

kjaymiller avatar Sep 23 '25 11:09 kjaymiller

Also pinging @brass75 - I know that you added the custom code logic directly to Blog and this issue predates you.

kjaymiller avatar Sep 23 '25 11:09 kjaymiller