bdragon300 / mongoengine-migrate

Migrations for MongoEngine inspired by Django
Apache License 2.0
17 stars 5 forks source link

`parameters` arg in `Schema.Document` constructor also adds `parameters` key to schema #33

Closed bdragon300 closed 3 years ago

bdragon300 commented 3 years ago

Now parameters arg in Schema.Document constructor also adds schema key with given value along with .parameters attribute:

>>> print(Schema.Document(a=1, b=2, parameters={5: 6}))
Document({'a': 1, 'b': 2, 'parameters': {5: 6}}, parameters={5: 6})

Should be:

>>> print(Schema.Document(a=1, b=2, parameters={5: 6}))
Document({'a': 1, 'b': 2}, parameters={5: 6})
vmdhhh commented 3 years ago

@bdragon300 I tried fixing this in #36. The only thing is if the user also wants to use parameters as key, then it should be given in {key: value} format. Otherwise, it will raise a SyntaxError: keyword argument repeated. Please have a look. EDIT: After looking at the build fail, I realized that for this to work, few things need to be changed.

bdragon300 commented 3 years ago

@vmdhhh Yes, I've inserted lines smth like del ...['parameters'] to unit tests as temp workaround for this problem. Now they may be removed then, most of errors in build are tied up with this.

bdragon300 commented 3 years ago

@vmdhhh parameters should be passed as keyword arg, other Schema.Document contents may be passed as dict or keyword args. It's behavior should be similar to built-in dict, except for parameters arg. For example:

print(Schema.Document(a=1, b=2, parameters={5: 6}))
Document({'a': 1, 'b': 2}, parameters={5: 6})

or

print(Schema.Document({'a': 1, 'b': 2}, parameters={5: 6}))
Document({'a': 1, 'b': 2}, parameters={5: 6})   #The same

or even

print(Schema.Document((('a', 1), ('b': 2)), parameters={5: 6}))
Document({'a': 1, 'b': 2}, parameters={5: 6})   #The same

but

print(Schema.Document({'a': 1, 'b': 2, 'parameters': {'key1', 'value1'}}, parameters={5: 6}))
Document({'a': 1, 'b': 2, 'parameters': {'key1', 'value1'}}, parameters={5: 6}) 

Just doing kwargs.pop before __init__ is sufficient, but it's needed to fix unit tests

vmdhhh commented 3 years ago

@vmdhhh Yes, I've inserted lines smth like del ...['parameters'] to unit tests as temp workaround for this problem. Now they may be removed then, most of errors in build are tied up with this.

I removed the "deletes". Seems that was only the problem.