Skip to content

Shouldn't the scope of the unique validation be the resource, instead of the collection? #1291

@arnauorriols

Description

@arnauorriols

After this change, the unique attributes must be unique for the entire MongoDB collection. Previously, they had to be unique only for the API resource. This becomes a problem when the datasource is configured with a filter and you have multiple resources sharing the same database collection.

At first we thought this was just a bug. However, in the mentioned commit a comment is introduced indicating that the change is in fact intentional:

we perform the check on the native mongo driver (and not on
app.data.find_one()) because in this case we don't want the usual
(for eve) query injection to interfere with this validation. We
are still operating within eve's mongo namespace anyway.

However, I fail to understand its motivation. Can you elaborate?

We don't use the soft-delete feature ourselves, but looking at the code, seems like it should also be affected (ie soft-deleted documents will be taken into account when validating the uniqueness of an attribute).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions