Skip to content
This repository has been archived by the owner on Jun 27, 2020. It is now read-only.

[django] Generalize uuid/key/receive_url logic (openwisp/openwisp-utils#40) #109

Merged
merged 1 commit into from
Jan 22, 2020

Conversation

waleko
Copy link
Contributor

@waleko waleko commented Jan 16, 2020

Removed the logics which were duplicated
in the others modules and redefined it here to enable reusability and ease debugging.

Related to openwisp/openwisp-utils#40

@waleko
Copy link
Contributor Author

waleko commented Jan 16, 2020

There is a key field in Topology model. I changed it to

key = KeyField(unique=False,
               db_index=False,
               help_text=_('key needed to update topology from nodes '),
               verbose_name=_('key'),
               blank=True)

But now when I run makemigrations I get this error:
TypeError: Couldn't reconstruct field key on django_netjsongraph.Topology: __init__() missing 2 required positional arguments: 'unique' and 'db_index'.

Presumably, changing CharField to KeyField for old data somehow doesn't include unique and db_index arguments in the constructor of KeyField. You can see the whole commit in my commit here. I also tried to fake the migrations file and then running migrate, but I get almost the same error: TypeError: __init__() missing 2 required positional arguments: 'unique' and 'db_index'.

The easy fix is of course to ditch KeyField, and just have CharField, but I would only do it as a last resort. Can you please help?

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the repo there's a get_random_key which you should be able to remove

@waleko
Copy link
Contributor Author

waleko commented Jan 17, 2020

Travis fails for python 2.7 because django-model-utils>=4.0.0,<4.1.0 requires Django>=2.0.1

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok no worries for the failing build on python 2.7 because i'm waiting for PR #99 to be merged which will fix it (@pawelplsi that's one of the reasons I'm insisting with finishing that PR).

I have only one minor request see below.

name='key',
field=openwisp_utils.base.KeyField(blank=True, default=openwisp_utils.utils.get_random_key, help_text='key needed to update topology from nodes ', max_length=64, validators=[django.core.validators.RegexValidator(re.compile('^[^\\s/\\.]+$'), code='invalid', message='This value must not contain spaces, dots or slashes.')], verbose_name='key'),
),
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this migration file should not be needed now that you updated the old migration file, you can remove it

Copy link
Contributor Author

@waleko waleko Jan 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nemesisdesign I updated old migration file, so that it's old generator (which was in django_netjsongraph.utils) wouldn't be needed, as I deleted it from there. But in the new migration I change the entire field type. So it seems to me, that we still need new migration file. I can of course update the old file once again to make it also KeyField, but I think it's better the way it is.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the entire field in the old migration file

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress! Please rebase your changes on the current master and see my comments below.

.travis.yml Outdated
@@ -28,6 +28,9 @@ before_install:
install:
- pip install $DJANGO
- if [[ $TRAVIS_PYTHON_VERSION == 2.7 ]]; then pip install -U "djangorestframework<3.10"; fi
# Temporary: remove when openwisp-utils#71 is merged
- pip install "https://github.com/waleko/openwisp-utils/tarball/issues/40" --upgrade
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I released openwisp-utils 0.4.1 which contains your patch openwisp/openwisp-utils#71.
You can now remove this temporary addition.

name='key',
field=openwisp_utils.base.KeyField(blank=True, default=openwisp_utils.utils.get_random_key, help_text='key needed to update topology from nodes ', max_length=64, validators=[django.core.validators.RegexValidator(re.compile('^[^\\s/\\.]+$'), code='invalid', message='This value must not contain spaces, dots or slashes.')], verbose_name='key'),
),
]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the entire field in the old migration file

requirements.txt Outdated
@@ -2,6 +2,6 @@ django>=1.11,<2.3
djangorestframework>=3.3,<3.12
django-model-utils
netdiff>=0.6.0,<0.7
openwisp-utils>=0.3,<0.4
openwisp-utils>=0.4,<0.5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use 0.4.1

@@ -1,4 +1,4 @@
coveralls
responses
freezegun
openwisp-utils[qa]>=0.3.0
openwisp-utils[qa]>=0.4.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use 0.4.1

Copy link
Member

@nemesifier nemesifier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, thank you! 👍

@nemesifier nemesifier merged commit d47b251 into openwisp:master Jan 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants