Skip to content

Migrate to django-environ #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

tkdchen
Copy link

@tkdchen tkdchen commented Oct 6, 2019

This patch uses django-environ and drop deprecated and old packages
django-cache-url, dj-email-url, dj-database-url and dj-cache-url.

Tests are updated according to the behavior of django-environ.

Signed-off-by: Chenxiong Qi [email protected]

This patch uses django-environ and drop deprecated and old packages
django-cache-url, dj-email-url, dj-database-url and dj-cache-url.

Tests are updated according to the behavior of django-environ.

Signed-off-by: Chenxiong Qi <[email protected]>
@codecov
Copy link

codecov bot commented Oct 6, 2019

Codecov Report

Merging #244 (f376341) into master (089a039) will decrease coverage by 0.32%.
The diff coverage is 100.00%.

❗ Current head f376341 differs from pull request most recent head fb7417f. Consider uploading reports for the commit fb7417f to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #244      +/-   ##
==========================================
- Coverage   90.08%   89.75%   -0.33%     
==========================================
  Files          27       25       -2     
  Lines        1210     1201       -9     
  Branches      101      107       +6     
==========================================
- Hits         1090     1078      -12     
- Misses         89       90       +1     
- Partials       31       33       +2     
Flag Coverage Δ
coverage 89.67% <100.00%> (?)
dj111 89.67% <100.00%> (?)
dj20 88.59% <100.00%> (?)
dj21 88.42% <100.00%> (?)
py27 89.09% <100.00%> (?)
py34 88.59% <100.00%> (?)
py35 88.59% <100.00%> (?)
py36 88.59% <100.00%> (?)
py37 88.59% <100.00%> (?)
pypy 89.09% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
configurations/values.py 95.22% <100.00%> (+0.90%) ⬆️
tests/test_values.py 100.00% <100.00%> (ø)
tests/settings/main.py 88.23% <0.00%> (-1.51%) ⬇️
configurations/base.py 82.45% <0.00%> (-0.88%) ⬇️
tests/test_main.py 95.23% <0.00%> (-0.51%) ⬇️
tests/urls.py 100.00% <0.00%> (ø)
tests/test_env.py 100.00% <0.00%> (ø)
tests/docs/conf.py 100.00% <0.00%> (ø)
tests/setup_test.py 100.00% <0.00%> (ø)
tests/test_sphinx.py 100.00% <0.00%> (ø)
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 089a039...fb7417f. Read the comment docs.

self.assertEqual(
cm.exception.args[0],
"Cannot interpret cache URL value 'redis://user@host:port/1'")
self.assertEqual(cm.exception.args[0], 'wrong')
Copy link
Contributor

Choose a reason for hiding this comment

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

That looks "wrong"?!
Shouldn't it have more info / a full msg?

Copy link
Author

Choose a reason for hiding this comment

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

django-environ simply raises KeyError when looking up a cache scheme by wrong, and here assertRaises catches the KeyError.

It might be good for django-envion to catch the KeyError and reraise a specific error with more descriptive message.

What do you think?

Copy link
Author

@tkdchen tkdchen Oct 11, 2019

Choose a reason for hiding this comment

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

FYI, I made a patch to django-environ, joke2k/django-environ#235

After this patch is accepted and merged, this assertion could be updated accordingly.

Copy link
Member

Choose a reason for hiding this comment

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

@tkdchen , that patch was merged; I guess this can be updated now ?

with env(EMAIL_URL='smtps://[email protected]:[email protected]:wrong'): # noqa: E501
self.assertRaises(ValueError, value.setup, 'TEST')

def test_cache_url_value(self):
cache_setting = {
'default': {
'BACKEND': 'django_redis.cache.RedisCache',
'LOCATION': 'redis://host:6379/1',
'LOCATION': 'redis://user@host:6379/1',
Copy link
Contributor

Choose a reason for hiding this comment

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

Apparently it changes some defaults (more secure by default).

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure if I get your point. Is this change acceptable?

Copy link
Contributor

Choose a reason for hiding this comment

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

It changes defaults apparently, so we should bump the major or at least minor version for it.

'EMAIL_USE_TLS': True})
with env(EMAIL_URL='console://'):
with env(EMAIL_URL='consolemail://'):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that change required?
Is it related to https://github.com/psgs/ConsoleMail?

Copy link
Author

Choose a reason for hiding this comment

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

Is it related to https://github.com/psgs/ConsoleMail?

No. I'm not aware of ConsoleMail. What I learned from django-environ is only consolemail is defined in email schemes, but no console. The consolemail maps to same backend django.core.mail.backends.console.EmailBackend.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's another behavior change then apparently AFAIK.

All those might be fine, and it's good to modernize, but might break setups/configs.

Copy link
Author

Choose a reason for hiding this comment

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

Hi @blueyed, I added another commit to make console:// still work in apps using it, and deprecate console://.

setup.py Outdated
'django-cache-url>=1.0.0',
'dj-database-url',
'dj-email-url',
'dj-search-url',
'six',
'Sphinx>=1.4',
],
Copy link
Contributor

Choose a reason for hiding this comment

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

Could maybe still be in extras_require?

Copy link
Author

Choose a reason for hiding this comment

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

Looks no need here. How useful to keep those in extra_require?

Copy link
Contributor

Choose a reason for hiding this comment

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

It avoids having to install / installing it by default when not needed.

I guess the typical usecase is using URLs for configs then, so that seems to be OK.

Apps using schema console:// still works, which is converted to
consolemail:// internally in order to work with django-environ.
Meanwhile, a deprecation warning is output for console://.

Signed-off-by: Chenxiong Qi <[email protected]>
@tkdchen tkdchen force-pushed the migrate-to-django-environ branch from e04768c to f376341 Compare October 12, 2019 03:47
@pauloxnet
Copy link
Member

I think django-environ is a strong addiction. I would prefer to leave django-configuration as light as possible.

@danpalmer
Copy link

Hi team / @tkdchen any update on this? It looks like all code review has been addressed. Would be great to get this merged!

@pauloxnet What's your reasoning for having django-configurations "as light as possible"? I think this is a positive change because:

  • it unifies more of the Python ecosystem on to django-environ as the parser for configuration URLs
  • this means more consistency and interoperability with other packages or in other environments
  • it removes 4 dependencies that need to be managed/bumped/etc, so in a way is "lighter"

@carltongibson
Copy link
Member

Hi folks.

Can you see also django/django#13029 and the related mailing list discussion?

tl;dr: Maybe we pull something into Django here. Perhaps it makes sense to have env vars read by the default project templates, but we should get right exactly what that should look like, and I don't want us to reinvent something that's already solved™ by the community.

It would be good to get your thoughts as contributors here.

Thanks 😉
C.

Copy link

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

I am very positive about this change moves o django-environ. can we just rebase and get this merged

@brianhelba
Copy link
Contributor

@auvipy It looks like @pauloxnet (who is now helping to maintain this project) objects to this change:

I think django-environ is a strong addiction. I would prefer to leave django-configuration as light as possible.

Could we get a consensus before merging this? If you (@auvipy) are planning to merge things yourself, could you please join the maintainer team and communicate your intentions with the rest of us: #295 (comment)


@pauloxnet Do you still object to this? It looks like django-environ is actively being maintained, whereas it looks like at least dj-database-url is unmaintained and in some sort of strange fork state. In particular, can you respond to @danpalmer's comment:

@pauloxnet What's your reasoning for having django-configurations "as light as possible"? I think this is a positive change because:

  • it unifies more of the Python ecosystem on to django-environ as the parser for configuration URLs
  • this means more consistency and interoperability with other packages or in other environments
  • it removes 4 dependencies that need to be managed/bumped/etc, so in a way is "lighter"

Copy link
Contributor

@brianhelba brianhelba left a comment

Choose a reason for hiding this comment

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

@auvipy There are a some issues with your recent merge. See inline comments.

setup.py Outdated
'testing': [
'django-discover-runner',
'mock',
'django-cache-url>=1.0.0',
'dj-database-url',
'dj-email-url',
Copy link
Contributor

Choose a reason for hiding this comment

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

These 4 packages need to be removed from the testing extra too.

Copy link
Contributor

@brianhelba brianhelba left a comment

Choose a reason for hiding this comment

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

The docs for these Value types need to be updated too, as they contain references to the old upstream packages: https://github.com/jazzband/django-configurations/blob/master/docs/values.rst#url-based-values

Users looking for precise syntax info should be pointed to django-environ docs instead.

@brianhelba brianhelba mentioned this pull request Oct 27, 2021
8 tasks
@pauloxnet
Copy link
Member

@pauloxnet Do you still object to this? It looks like django-environ is actively being maintained, whereas it looks like at least dj-database-url is unmaintained and in some sort of strange fork state. In particular, can you respond to @danpalmer's comment

I'm going to review again this PR but the main guidelines for me is similar to the one used by Django to strongly avoid to depend on other packages, or depend only on trusted, maintained and really necessary ones.

Asif Saif Uddin and others added 3 commits October 27, 2021 14:13
Co-authored-by: Brian Helba <[email protected]>
Co-authored-by: Brian Helba <[email protected]>
Co-authored-by: Brian Helba <[email protected]>
@auvipy
Copy link

auvipy commented Oct 27, 2021

@auvipy It looks like @pauloxnet (who is now helping to maintain this project) objects to this change:

I think django-environ is a strong addiction. I would prefer to leave django-configuration as light as possible.

Could we get a consensus before merging this? If you (@auvipy) are planning to merge things yourself, could you please join the maintainer team and communicate your intentions with the rest of us: #295 (comment)

@pauloxnet Do you still object to this? It looks like django-environ is actively being maintained, whereas it looks like at least dj-database-url is unmaintained and in some sort of strange fork state. In particular, can you respond to @danpalmer's comment:

@pauloxnet What's your reasoning for having django-configurations "as light as possible"? I think this is a positive change because:

  • it unifies more of the Python ecosystem on to django-environ as the parser for configuration URLs
  • this means more consistency and interoperability with other packages or in other environments
  • it removes 4 dependencies that need to be managed/bumped/etc, so in a way is "lighter"

I just shared my suggestion. but i strongly believe moving to django-environ would a good move. even django core tried that way.

@auvipy
Copy link

auvipy commented Oct 27, 2021

Also in my humble opinion @pauloxnet reasoning on blocking this is not valid. even if he is maintaining this project he do not have enough contribution history to the project. I am also interested to join the team as well. no offense just sharing my honest thoughts.

@pauloxnet
Copy link
Member

Also in my humble opinion @pauloxnet reasoning on blocking this is not valid. even if he is maintaining this project he do not have enough contribution history to the project. I am also interested to join the team as well. no offense just sharing my honest thoughts.

No offense at all, you're totally right, but at the same time I'm using this package in a lot of projects as many other users I think that want their projects continue running.

This is PR is a huge changes for this project, it add a totally new dependency and it's not retro compatible.

If you really think start using django-environ is a good move for the project then we have to define a strict goal checks to verify that ti move will not brake project using it and replace all current features (e.g. I see some tests has been removed and it's seems because django-environ can't pass them).

However I think it's a better idea to release the 2.3 version.

@auvipy
Copy link

auvipy commented Oct 27, 2021

it would be better in a v3.0 release

@uhurusurfa
Copy link
Contributor

I would agree with @pauloxnet on this one and would go a step further by creating an internal URL checker and converter to remove the dependencies on the 3 external packages. I had to fix a unit test that started failing due to a change in dj_database_url
I would propose closing this PR unless there remains strong opinions to move forward with the django-environ use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants