art049 / art049/odmantic

Support native validator

Open
#356 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
Python
Stars
1.2k
Forks
97
PR merge metrics
No merged PRs in 30d

Description

# Feature request

### Context

As I see - mongo has [his own validation](https://www.mongodb.com/docs/manual/core/schema-validation/). I saw sources - nothing about mongo validator.

### Solution

It will be pretty, if i can set validator in my schema, for example

```
class CapitalCity(Model):
name: str
population: int

class Config:
collection = "city"
validator = {...}
```
or if validator generated, based on pydantic schema
```
CapitalCity.model_json_schema()
```

### Additional context

In my opinion, it can be set when collection and index created:
```
engine = AIOEngine()
await engine.configure_database([CapitalCity])
```

### Why we need it, besides of code validation now?

So, i can't have an ideal answer. For me, it's necessary, if we communicate with db - validate it on multiple sides - in code and in db. Same things happen with relation db in sqlalchemy and sqlmodel.

One more example - frontend validation in html forms plus backend validation in schemas/serializers

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at AIOEngine.configure_database and inspect how the collection and indexes are created, then trace the model Config and model_json_schema entry points. Done means a schema can provide a MongoDB validator, or one can be generated from the Pydantic schema, and it is applied when the database is configured.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.