[BD-14] Updates Blockstore Python API [TNL-8746] [FAL-2702] - #149
Conversation
|
Thanks for the pull request, @pomegranited! I've created BLENDED-1068 to keep track of it in Jira. More details are on the BD-14 project page. When this pull request is ready, tag your edX technical lead. |
|
@pomegranited Thank you for your contribution. Please let me know once this is ready. |
b27603f to
40404f3
Compare
02efe57 to
7b11fa5
Compare
|
|
||
| So we detect this case here, and use a different db_collation if we're running on Sqlite. | ||
| """ | ||
| DB_COLLATION = 'binary' if 'sqlite' in settings.DATABASES['default']['ENGINE'] else 'utf8mb4_general_ci' |
There was a problem hiding this comment.
@symbolist @gabor-boros There's a database compatibility problem with the db_collation setting that was chosen for some of the fields in these models.
Blockstore tests and production use MySQL, so using db_collation='utf8mb4_general_ci' was fine.
However, my attempts to run the unit tests with blockstore installed have failed because edx-platform uses sqlite.
- Sqlite, doesn't support
utf8mb4_general_ci; the best it can do isbinary. - Postgres doesn't support
utf8mb4_general_cieither, and its use contradicts the Postgres compatibility as documented for these models. Postgres's closest built-in equivalent collation sequence is the standarducs_basic.
While it's relatively easy to configure the charset and collation sequence options at the settings.DATABASES level, we don't want to do this for all fields, and there isn't a nice way to do this per-field, except by modifying the model code directly.
So a full solution would require:
- detecting which database is in use for the given class, and
- returning an appropriate collation setting for that database engine.
All of which makes the model.py and the generated migrations pretty complicated, and difficult to reliably test and maintain.
@ormsbee has raised the very timely issue of whether we can formally drop support for Postgres, but that's a longer discussion.
Any suggestions for how to handle this better right now?
There was a problem hiding this comment.
Does it make sense to create a custom field that subclasses CharField and has the logic to apply database-specific collations during migrations? I think it's primarily two use cases:
- Human-readable text that should be collated to be case-insensitive and as aware of accents, etc. as possible.
- Identifiers, which should be case sensitive.
?
There was a problem hiding this comment.
I think the tests don't depend on unicode-aware cast insensitive sorting, so binary should work fine for test purposes? The main thing they test is that all unicode characters including emojis can be used without issue, and binary should be fine for that.
And yeah +1 to what Dave is suggesting.
There was a problem hiding this comment.
I think the tests don't depend on unicode-aware cast insensitive sorting,
Yep, this hack works for testing, but it's not pretty, and doesn't handle the Postgres use case.
Does it make sense to create a custom field that subclasses CharField and has the logic to apply database-specific collations during migrations?
Interesting suggestion, @ormsbee.. a custom field class seems doable, but it will still need to be passed information about the database selected for the migration so that it can exhibit the best field options for that engine. I'd have to dig into Django's field and migration logic to see if that can be done with the existing auto-generated migrations or not, but it's worth a try!
Since this is likely something that would be broadly useful outside of Blockstore, is there an openedx repo that would be an appropriate place for this change to live?
I'm going to have to leave this hack in place right now though, and create a follow-up task for this, since it's out of scope for this change.
There was a problem hiding this comment.
Since this is likely something that would be broadly useful outside of Blockstore, is there an openedx repo that would be an appropriate place for this change to live?
edx-django-utils is probably what you want. It's installed on pretty much every service.
eaf2d95 to
bd16240
Compare
f89b707 to
ce02814
Compare
symbolist
left a comment
There was a problem hiding this comment.
Reviewed this as part of openedx/openedx-platform#29779. Looks good to launch! 🚀
Once this has been merged, I am assuming we will deploy this to the blockstore service as well? Before merging openedx/openedx-platform#29779 i.e..
|
Thank you for your review @symbolist ! @bradenmacdonald is going to have a look as core committer, and then I can squash the changes in preparation for merge.
Hi @jristau1984 I see you're the Reporter for TNL-8746. Can you help us find someone to shepherd this through to release on to edX's blockstore service? |
|
@pomegranited our team planned our sprint yesterday, so this was not included. I will ensure this is discussed in our next sprint planning (March 14). Please let me know if that does not work for your team. Thanks! |
|
Brilliant, thank you @jristau1984 ! I think MIT are awaiting this change too, so I'll forward your timeline details to them. There's a few steps required to merge and deploy all of this:
|
bradenmacdonald
left a comment
There was a problem hiding this comment.
I read through the code and it looks good to me, thanks! I tested the sandbox on openedx/openedx-platform#29779 but will generally rely on @symbolist 's testing here.
|
We (at MIT) are eager to see this merged, but our deployment is on maple so we need some additional work before we can actually test it. However, we don't have an existing deployment of blockstore, so most of the steps after "merge and tag" are irrelevant to us. We'll keep an eye on this, and openedx/openedx-platform#29779 to see when they merge. |
|
[Update] T&L has pulled this into our sprint starting today. @doctoryes will be driving the work from our side. Thanks! |
|
@jristau1984 Thanks! @doctoryes Since these changes, particularly openedx/openedx-platform#29779 are risky, will you be able to share the rollout plan and deployment windows with us whenever you have done the initial planning so we can have labxchange firefighters available to monitor the roll-out? Thanks! |
|
@symbolist Yes, I will do so. I'm currently working on the infrastructure changes needed for LMS to access the blockstore DB. Once I have an idea of when I'll finish that work, I'll let you know. |
|
@doctoryes thanks! |
|
@pomegranited : Some additional work has presented itself for this repo's transition to Django application: The @symbolist is aware of the need for this addition - but just wanted to mention it here as well. |
|
Is there a new etm (estimate time to merge) for this PR and it's companion openedx/openedx-platform#29779? |
|
@pomegranited @symbolist : The work was merged to allow access from the edx.org stage and production environments to the blockstore DB. The blockstore DB should now be accessible from Django in both the edxapp web and worker instances using a DB alias of blockstore. |
|
@pomegranited 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
|
@doctoryes Great, thanks! Before we install this in edxapp, we should deploy the changes to the blockstore service. Can we do this on Monday? The steps after that should be:
Does TNL have capacity over the next two weeks to support this deployment? CC @pdpinch |
|
@pdpinch Do you need this on the head of the master branch or on a named release? |
|
@symbolist In this repo, it can be in the master branch. I don't think BTR is ready to support blockstore as part of nutmeg. It would be best if the openedx/openedx-platform#29779 could be in nutmeg (RC to be cut April 9) |
|
Thank you for merging this @symbolist ! Could you (or @doctoryes ) tag the latest master so I can reference it in openedx/openedx-platform#29779? The current version is |
|
@pomegranited I have created the |
|
Brilliant, thank you @doctoryes ! I've updated the blockstore requirement on openedx/openedx-platform#29779.
I agree, but I haven't seen that mentioned anywhere. @farhaanbukhsh or @kaustavb12 is that something that would fit into the BD-14 epic? |
|
@pomegranited This PR caused the latest Blockstore deploy as an IDA (not as a Django app in edx-platform yet) to fail with this error: I see that
This missing config will need to be fixed first before proceeding with deploying Blockstore-as-a-Django-app in edx-platform. FYI @symbolist |
|
@doctoryes Oh bummer.. I missed that issue with my testing :( I've submitted #166 to resolve this issue, but an interim option would be to add the following to edx-internal: BUNDLE_ASSET_STORAGE_SETTINGS:
STORAGE_CLASS: 'storages.backends.s3boto3.S3Boto3Storage'
STORAGE_KWARGS: {}As noted in #166, the storage kwargs will be pulled from the top-level settings; the only issue here is that I didn't allow that dict to be omitted. |
@symbolist there's a problem -- if we add So we're going to have to detect which database is the actual one being used to applying with this wrapper. Ugh! |
|
NVM @symbolist , you addressed this issue on Slack. Thank you! |
Description
Continues the work started by #140, and makes the remaining changes necessary for the Blockstore as app ADR: #71.
Replaces #97.
Author Comments, Concerns, and Open Questions
See #97 for discussions.
Test Instructions
See openedx/openedx-platform#29779.
TODOs
Next steps
Once these PRs merge, we will need to:
Clean up the edx-platform codebase:
openedx.core.lib.blockstore_apiwithblockstore.app.api.Clean up the blockstore codebase:
blockstore.apps.core.blockstore.app.rest_apitagstorecode.