xncbf / django-dynamodb-cache

Django cache backend for serverless
https://pypi.org/project/django-dynamodb-cache/
MIT License
31 stars 5 forks source link

Add a database arg #17

Closed symroe closed 1 year ago

symroe commented 1 year ago

Django's createcachetable allows passing in a database arg.

This is called when Django creates a test database, as per:

https://github.com/django/django/blob/4.1/django/db/backends/base/creation.py#L96

This line is hit when using pytest and pytest-django, however it might also be hit in other testing setups.

The change in this commit adds a "dummy" arg to the command that fixes this problem.

codecov-commenter commented 1 year ago

Codecov Report

Base: 89.73% // Head: 89.73% // No change to project coverage :thumbsup:

Coverage data is based on head (906465d) compared to base (1bdaed3). Patch coverage: 100.00% of modified lines in pull request are covered.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #17 +/- ## ======================================= Coverage 89.73% 89.73% ======================================= Files 11 11 Lines 302 302 ======================================= Hits 271 271 Misses 31 31 ``` | [Impacted Files](https://codecov.io/gh/xncbf/django-dynamodb-cache/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Joon+Hwan+%EA%B9%80%EC%A4%80%ED%99%98) | Coverage Δ | | |---|---|---| | [...modb\_cache/management/commands/createcachetable.py](https://codecov.io/gh/xncbf/django-dynamodb-cache/pull/17?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Joon+Hwan+%EA%B9%80%EC%A4%80%ED%99%98#diff-ZGphbmdvX2R5bmFtb2RiX2NhY2hlL21hbmFnZW1lbnQvY29tbWFuZHMvY3JlYXRlY2FjaGV0YWJsZS5weQ==) | `100.00% <100.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Joon+Hwan+%EA%B9%80%EC%A4%80%ED%99%98). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Joon+Hwan+%EA%B9%80%EC%A4%80%ED%99%98)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

xncbf commented 1 year ago

Welcome to your first PR 🥳

symroe commented 1 year ago

I did think a little more about a larger change for this that I thought it might be useful to share:

Django's other cache backends don't actually implement a management command to make the database.

I think the assumption is that it can connect to the database that in turn creates the "table" that the backend needs.

I wonder if this library could ditch the createcachetable management command in favour of making the table on the fly, and maybe implement a check that can report when using manage.py --check.

The problem with this is that projects might break in production if the user doesn't have CreateTable permissions, but this might be the case at the moment with the management command.

xncbf commented 1 year ago

Does that mean you don't need the createcachetable command? Is it because it automatically creates the table in general?