Conversation
|
It seems there's still some flakiness in the test suite. |
Yeah, don't have any control over that, it's due to rate limits when pulling the Mongo Docker image. Perhaps we can look into caching it somehow... I have rerun the failing job. |
|
@volfpeter Regarding the PR and the functionality, I have just quickly glanced over it, it looks good to me. Will try it out and test it when I get the time. |
Thanks for the quick feedback. When the code change itself is accepted, I'll add the related documentation. Honestly, I'm not too happy with the I'm also not happy about settings inheritance, it's easy to use incorrectly and not that intuitive, mainly because of settings names. There is one alternative I can think of (besides the one I implemented in my earlier PR), but first I implemented what was requested. The alternative is using class MyDocument(Document, class_id="value-for-class-id-field"):
...This pattern is also used by |
|
Again, I have no strong opinions here. |
|
Well, here is how it would work with settings (as requested in #1133): class VehicleSettings:
is_root = True
name = "vehicles"
class_id = "type"
class VehicleWithCustomClassId(Document):
class Settings(VehicleSettings): ...
class BicycleWithCustomClassId(VehicleWithCustomClassId):
class Settings(VehicleSettings):
class_id_value = "bicycle"
...
class CarWithCustomClassId(VehicleWithCustomClassId, Fuelled):
class Settings(VehicleSettings):
class_id_value = "car"
...And here is the same with class VehicleWithCustomClassId(Document):
class VehicleSettings:
is_root = True
name = "vehicles"
class_id = "type"
class BicycleWithCustomClassId(VehicleWithCustomClassId, id="bicycle"):
...
class CarWithCustomClassId(VehicleWithCustomClassId, Fuelled, id="car"):
...I feel the |
|
My preference is for the configuration option in the model Settings subclass, as it follows Beanie's current design and API. class Vehicle(Document):
class Settings:
is_root = True
class_id = "type"
class_id_value = "vehicle"
class Bicycle(Vehicle):
class Settings:
class_id_value = "bicycle"which IMHO looks good. |
|
Okay, I'm happy with this, I don't need to rewrite the PR another time. I'm not sure your example would work, because |
Your example code doesn't work, because if a document class declares its own settings, then it fully overwrites the settings declaration of the parent class. So if you don't use explicit settings inheritance as in my example, the you need to set |
This sentence from my previous reply is key:
Otherwise yes, because you are using class inheritance, you would have to repeat/override the wanted parameters. Beanie does not anywhere state that Settings inheritance should (or shouldn't) be used, in all examples there is no inheriting of Settings class shown. Regarding this:
This would be that |
class_id_value handling
|
Oh, my bad. Apparently the current implementation works without explicit settings inheritance. I updated the test models to use that version. It's quite good this way (except for the settings names, but that's a fix for the next major version). |
|
I've added a bit of documentation. There wasn't much documentation for the @staticxterm Do you have an idea why all Pydantic v1 jobs are failing? I'm not too familiar with the test suite or the Pydantic v1 support status. It's strange that the Pydantic This is in the install log (copied from a failed job: |
|
@staticxterm Could you maybe review the PR? The actual code change is about 10 lines, plus documentation with examples. The remaining 80% is testing: I mirrored the standard inheritance models and tests, but with a mix of user-defined and auto-calculated class ID values to make sure everything is tested properly. |
|
@staticxterm @volfpeter |
|
I see there has been discussion here. The feature is useful but the current approach (requiring settings subclasses in every model) is not ideal ergonomically. Will revisit this after the current batch of bug fixes lands. |
|
Thanks @roman-right. Appreciate it |
|
Thanks @roman-right Other ideas that came up so far:
Let me know what you think. I'm happy to spend time on alternative implementations if a different path is chosen. |
|
Thanks a lot! |
Closes #1132
For reference, this is a re-implementation of #1133 using settings to set the class ID value (as requested in that PR by @staticxterm ).
This solution has some quirks in comparison with #1132, notably the need for creating a base settings class and using subclasses in every model in the inheritance chain.