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

fix: wait for transaction commit before trying to sink models #90

Merged
merged 8 commits into from
Oct 4, 2024

Conversation

Ian2012
Copy link
Contributor

@Ian2012 Ian2012 commented Sep 11, 2024

Closes: #90
Merge checklist:
Check off if complete or not applicable:

  • Version bumped
  • Changelog record added
  • Documentation updated (not only docstrings)
  • Fixup commits are squashed away
  • Unit tests added/updated
  • Manual testing instructions provided
  • Noted any: Concerns, dependencies, migration issues, deadlines, tickets

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Sep 11, 2024
@openedx-webhooks
Copy link

Thanks for the pull request, @Ian2012!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @bmtcril. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

Copy link

github-actions bot commented Sep 11, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  platform_plugin_aspects
  __init__.py
  signals.py 77-93, 191, 229, 267
Project Total  

This report was generated by python-coverage-comment-action

@bmtcril
Copy link
Contributor

bmtcril commented Sep 23, 2024

I've been trying to test this but have only been able to trigger the course related sinks, not the user profile / external_id sinks or the taxonomy / tag / object_tag. Any ideas what I may be missing? Config looks like:

EVENT_SINK_CLICKHOUSE_PII_MODELS = ['user_profile', 'external_id', 'auth_user']
...
EVENT_SINK_CLICKHOUSE_COURSE_OVERVIEWS_ENABLED = True
EVENT_SINK_CLICKHOUSE_TAG_ENABLED = True
EVENT_SINK_CLICKHOUSE_TAXONOMY_ENABLED = True
EVENT_SINK_CLICKHOUSE_OBJECT_TAG_ENABLED = True
EVENT_SINK_CLICKHOUSE_COURSE_ENROLLMENT_ENABLED = True
# User PII models
EVENT_SINK_CLICKHOUSE_USER_PROFILE_ENABLED = True
EVENT_SINK_CLICKHOUSE_EXTERNAL_ID_ENABLED = True
EVENT_SINK_CLICKHOUSE_AUTH_USER_ENABLED = True 

Nothing shows in the worker logs when these get triggered. The known Celery tasks for platform-plugin-aspects only show:

  . platform_plugin_aspects.tasks.dump_course_to_clickhouse
  . platform_plugin_aspects.tasks.dump_data_to_clickhouse

@Ian2012 Ian2012 force-pushed the cag/tag-txn branch 2 times, most recently from 359a214 to 04f57c2 Compare September 23, 2024 20:22
platform_plugin_aspects/signals.py Outdated Show resolved Hide resolved
Copy link
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

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

Aside from user profile being broken, I've tested the following successfully:

  • external id
  • course enrollment
  • course publish
  • add / delete tags to objects

Things I haven't been able to test:

  • user retirement
  • taxonomy saved

lambda: on_user_profile_updated(kwargs["instance"])
) # pragma: no cover

def on_user_profile_updated(instance):
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like there is an issue here:

2024-10-01 15:11:04,575 ERROR 1 [django.request] [user 6] [ip 192.168.247.1] log.py:241 - Internal Server Error: /api/user/v1/accounts/bmtcril
Traceback (most recent call last):
  File "/openedx/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/openedx/venv/lib/python3.11/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/pyenv/versions/3.11.8/lib/python3.11/contextlib.py", line 80, in inner
    with self._recreate_cm():
  File "/openedx/venv/lib/python3.11/site-packages/django/db/transaction.py", line 307, in __exit__
    connection.set_autocommit(True)
  File "/openedx/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 501, in set_autocommit
    self.run_and_clear_commit_hooks()
  File "/openedx/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 779, in run_and_clear_commit_hooks
    func()
  File "/mnt/platform-plugin-aspects/platform_plugin_aspects/signals.py", line 93, in <lambda>
    transaction.on_commit(lambda: on_user_profile_updated(**kwargs))
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: on_user_profile_updated_txn.<locals>.on_user_profile_updated() got an unexpected keyword argument 'signal'

Changing it to def on_user_profile_updated(sender, instance, **kwargs): seemed to fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated. The taxonomy saved workflow can be tested from the django admin

Copy link
Contributor

@bmtcril bmtcril left a comment

Choose a reason for hiding this comment

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

Probably not related to your changes, but the retirement sink fails now trying to delete from event_sink.auth_user, which we never create. I think this is a bug in tutor-contrib-aspects, but just in case you can think of a reason why it might be related here I'm mentioning it.

Removing auth_user from the EVENT_SINK_PII_MODELS in tutor-contrib-aspects seemed to fix it for me, but I'm still not 100% sure it did the right thing.

Approving this on the assumption it's unrelated to this PR.

@Ian2012
Copy link
Contributor Author

Ian2012 commented Oct 1, 2024

Yeah, it's assuming that the setting: EVENT_SINK_CLICKHOUSE_PII_MODELS contains a list of tables to delete records where the column user_id is present. We need to create a new setting that keeps track of those tables (external_id, user_profile) and any new one. Not related

@bmtcril
Copy link
Contributor

bmtcril commented Oct 4, 2024

This one should be ready to go if you want to bump the version

@Ian2012 Ian2012 merged commit 0775832 into main Oct 4, 2024
10 checks passed
@Ian2012 Ian2012 deleted the cag/tag-txn branch October 4, 2024 18:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants