Skip to content
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

Fixed #28184 -- Allowed passing a callable storage to FileField. #8477

Merged

Conversation

miigotu
Copy link
Contributor

@miigotu miigotu commented May 8, 2017

Adds the ability to pass a callable as the storage param of FileField, and testing for this new ability

See ticket 28184 for details.

Signed-off-by: miigotu miigotu@gmail.com

@miigotu miigotu force-pushed the miigotu/filefield_storage_callable branch 6 times, most recently from 40ac0e4 to 8350a16 Compare May 8, 2017 23:08
@miigotu miigotu closed this May 8, 2017
@miigotu miigotu reopened this May 8, 2017
@miigotu miigotu force-pushed the miigotu/filefield_storage_callable branch from 8350a16 to b0a33ed Compare May 8, 2017 23:10
@miigotu miigotu closed this May 31, 2017
@miigotu miigotu reopened this May 31, 2017
@miigotu miigotu force-pushed the miigotu/filefield_storage_callable branch 3 times, most recently from 4a1f1e3 to 489d963 Compare May 31, 2017 19:15
@timgraham timgraham changed the title Fixes #28184 - Add ability to pass a callable as the storage param to FileField, with tests Fixed #28184 -- Allowed passing a callable storage to FileField. Jun 19, 2017
Copy link
Member

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

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

Hi @miigotu

Thanks for the effort here. Are you still up for finishing this PR?

Some comments to be addressed:

  1. The CI build still has failures, specifically isort and flake8. Can you rebase and address those please?
  2. "What happens if you don't return a valid storage type?" — It's worth adding a test here. Since we can check at import time it's worth checking we get a valid return type, and probably raising ImproperlyConfigured with a helpful message if not. (Does it actually blow up immediately, or do you get a runtime error later? Is that error clear — i.e. does it instantly show what the problem is? — Etc. Better to head these off at the pass.)
  3. Docs.

Let me know if you need any input.

@miigotu
Copy link
Contributor Author

miigotu commented Feb 28, 2018

Yes, I'll fix the build first and then see about the other checks. About the type checking though, there is also no type checking in other places callables are allowed so I just did it the same way. I'll test what exactly DOES happen and see for sure.

@miigotu miigotu force-pushed the miigotu/filefield_storage_callable branch from 692763c to 518e6aa Compare February 28, 2018 20:06
Copy link
Member

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

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

Hi @miigotu.

Thanks for the updates. A couple of quick points...

tests/file_storage/tests.py Outdated Show resolved Hide resolved
django/db/models/fields/files.py Outdated Show resolved Hide resolved
@miigotu miigotu force-pushed the miigotu/filefield_storage_callable branch 8 times, most recently from ccaa51a to 446e6db Compare March 2, 2018 08:54
@miigotu
Copy link
Contributor Author

miigotu commented Mar 2, 2018

This is going to take me a bit more work/thought. These tests fail on master for me also.

@carltongibson
Copy link
Member

Hi @miigotu — GH's review panel seems to be failing me this morning... I'll try a comment 😄

Sorry if this ends up appearing several times.


Hi @miigotu

Thanks for updating here. It's looking good. 👍

Does this have to wait until 2.2 now or is it allowed in 2.1.3?

It's a new feature so, it'll have to go in 2.2. Can you update accordingly?

docs/topics/files.txt:185
Feels a bit nit-picky but, is this quite right?

It's not that the storage is callable, but that the callable provides the storage... Maybe "Using a callable" or "...to specify the storage". ?

tests/file_storage/tests.py:866
Would this block be better using subTest()?

@miigotu miigotu force-pushed the miigotu/filefield_storage_callable branch 2 times, most recently from 535ca97 to 3b88530 Compare October 22, 2018 23:22
@miigotu
Copy link
Contributor Author

miigotu commented Oct 22, 2018

@carltongibson I've addressed the changes from your last comments, and added an unforeseen way to use this in the example (mostly to make sure someone doesn't add a call method to their storage class and something unexpected happen)

This build should pass, let me know if there are any other changes that need to be made, or if my added example is too much.

docs/releases/2.2.txt Outdated Show resolved Hide resolved
@miigotu miigotu force-pushed the miigotu/filefield_storage_callable branch from ed020dc to b5f7cd0 Compare June 21, 2019 09:02
@LuRsT
Copy link
Contributor

LuRsT commented Sep 17, 2019

@miigotu Need help with this PR?

@nikolaik
Copy link

nikolaik commented Mar 24, 2020

Would have used this feature today if merged. Any help wanted?

@miigotu
Copy link
Contributor Author

miigotu commented Mar 25, 2020

Yes. If you can get it ready I will accept PR to my repo. It will need rebased and updated.

@miigotu miigotu force-pushed the miigotu/filefield_storage_callable branch from cfec459 to f795976 Compare March 26, 2020 19:01
@carltongibson carltongibson force-pushed the miigotu/filefield_storage_callable branch from f795976 to e74c9d0 Compare March 31, 2020 10:42
Copy link
Member

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

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

Hi @miigotu @nikolaik.

Thanks for updating this. I pushed some edits to the docs.

Any chance we can add a test for the Storage subclass implementing __call__() case?

@miigotu
Copy link
Contributor Author

miigotu commented Apr 1, 2020

@carltongibson I'm not sure exactly what you mean? A failure case or a success case? Is it more to exemplify how someone could have a subclass of Storage that also has a __call__ method that returns an already instantiated storage attribute?

I guess I just don't understand the goal of that one, we currently handle it the same way any other place a callable is allowed to be passed into the model manager.

@carltongibson
Copy link
Member

Hi @miigotu. I pushed a fixup removing the callable storage example. I think it's probably clearer without it.

I'll ask @felixxm to have a look here.

Copy link
Member

@felixxm felixxm left a comment

Choose a reason for hiding this comment

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

@miigotu Thanks 👍 I left few suggestions.

django/db/models/fields/files.py Outdated Show resolved Hide resolved
django/db/models/fields/files.py Outdated Show resolved Hide resolved
django/db/models/fields/files.py Outdated Show resolved Hide resolved
docs/releases/3.1.txt Outdated Show resolved Hide resolved
docs/releases/3.1.txt Outdated Show resolved Hide resolved
tests/file_storage/tests.py Outdated Show resolved Hide resolved
tests/file_storage/models.py Outdated Show resolved Hide resolved
tests/file_storage/models.py Outdated Show resolved Hide resolved
docs/topics/files.txt Outdated Show resolved Hide resolved
docs/topics/files.txt Show resolved Hide resolved
@miigotu
Copy link
Contributor Author

miigotu commented Apr 2, 2020

@carltongibson Ahh, the callable storage example I forgot about that. So that is what you wanted a test case around, lol. I think it's probably clearer without it also, but it is one of the primary use cases where storage would adapt automagically ;)

I'll try and get some of these documentation changes in over the next few days f nobody else gets to it. I am shooting in the dark when doing this style of documentation since it's my first time.

@carltongibson carltongibson force-pushed the miigotu/filefield_storage_callable branch from 5fdc997 to c5587e3 Compare April 8, 2020 08:36
@carltongibson carltongibson force-pushed the miigotu/filefield_storage_callable branch from c5587e3 to 77632fa Compare April 8, 2020 08:43
@carltongibson carltongibson merged commit 94b32a2 into django:master Apr 8, 2020
@miigotu miigotu deleted the miigotu/filefield_storage_callable branch April 8, 2020 12:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants