{ "info": { "author": "David P Hilton", "author_email": "david.hilton.p@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Database" ], "description": "# Overview\n\nsqlalchemy_commithooks allows actions to be deferred until commit time.\nIt also allows for objects to take action if a commit *fails*.\n\nThis is useful for maintaining consistency with external systems, for example:\n\n * sending events\n * s3 synchronization\n * redis queue synchronization\n\nsqlalchemy_commithooks requires Python >=3.6. This would be hard (impossible?)\nto get around without changing the API or modifying sqlalchemy.\n\nThere is no overhead if a commit hook is unused.\n\n## Getting Started\n\nUse sqlalchemy_commithooks.Session instead of sqlalchemy.orm.Session.\nSessionMixin is also defined, if you are already subclassing Session:\n\n```python\nsession = sqlalchemy_commithooks.Session()\n```\n\nAdd sqlalchemy_commithooks.CommitMixin to your mapped class and use any of 9 hooks:\n\n```python\nclass Data(Base, sqlalchemy_commithooks.CommitMixin):\n def before_commit_from_insert(self):\n pass\n```\n\nThe hooks are available for all combinations of (`before`,\n`after`, `failed`) and (`insert`, `update`, `delete`).\n\nSimply override methods like `before_commit_from_insert`, `failed_commit_from_insert`,\n`after_commit_from_delete` etc.\n\n\n# Usage Notes\n\nbefore_commit_* will always fire, and one of after_commit_* or failed_commit_*\nwill fire, assuming two conditions are met.\n\n1. You handle your own exceptions in your \\*\\_commit_from\\_\\* handlers.\n2. [You are using sqlalchemy's recommended transaction semantics\n(commit/rollback)](http://docs.sqlalchemy.org/en/latest/orm/session_basics.html#when-do-i-construct-a-session-when-do-i-commit-it-and-when-do-i-close-it).\n\nIf an object is inserted (flushed), updated (flushed), deleted (flushed)\nand then commit is called, insert/update/delete methods will execute (in\nthat order) even though the object will not persist after the commit.\n\nUpdates in before_commit_* will be applied, but will not cascade/trigger any \n\\*\\_commit\\_from\\_\\* calls.\n\n## Limitations\n\nsqlalchemy_commithooks cannot solve all problems. As an example, it is not\nperfectly robust against network outages:\n\n```python\nDB.add(mapped_object)\nDB.commit()\n# before_commit_from_insert is run, puts an object into s3\n# network outage occurs now\n# actual commit to DB fails (network outage)\n# failed_commit_from_insert is run, fails to remove object from s3\n```\n\nFor each use case, you must determine what has priority.\n\nShould an notification be sent if the DB commit fails (notification is sent,\nthen network outage preventing full commit)? Or should an event notification\npossibly not be sent if the commit succeeds (transaction is committed, network\noutage prevents notification)?\n\n## TODO\n\n* add session.nested_transaction support\n* add cascade option\n* make it easy to see which hooks will run in the debugger\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/dhiltonp/sqlalchemy_commithooks", "keywords": "", "license": "mit", "maintainer": "", "maintainer_email": "", "name": "sqlalchemy-commithooks", "package_url": "https://pypi.org/project/sqlalchemy-commithooks/", "platform": "any", "project_url": "https://pypi.org/project/sqlalchemy-commithooks/", "project_urls": { "Homepage": "https://github.com/dhiltonp/sqlalchemy_commithooks" }, "release_url": "https://pypi.org/project/sqlalchemy-commithooks/1.2.8/", "requires_dist": [ "sqlalchemy" ], "requires_python": "", "summary": "Provides object-level commit hooks for SQLAlchemy", "version": "1.2.8" }, "last_serial": 4004829, "releases": { "1.2.8": [ { "comment_text": "", "digests": { "md5": "506f009b773a2bef84bcff630fe87661", "sha256": "1fcb5746791b45cea2a2556b98860f31f8509926a84695a25260ec04e5ac6576" }, "downloads": -1, "filename": "sqlalchemy_commithooks-1.2.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "506f009b773a2bef84bcff630fe87661", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7915, "upload_time": "2018-06-26T19:43:29", "url": "https://files.pythonhosted.org/packages/66/c3/02695f707e95740d9acfea4354a271d023c3d2a81195a3d7806807a0557f/sqlalchemy_commithooks-1.2.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2b39d0c3a3647cfb420c7a6971740f00", "sha256": "14536617d66f08c095f9abd629f205451e8d105d551f6537d0e98c5d5665eb75" }, "downloads": -1, "filename": "sqlalchemy_commithooks-1.2.8.tar.gz", "has_sig": false, "md5_digest": "2b39d0c3a3647cfb420c7a6971740f00", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9133, "upload_time": "2018-06-26T19:43:29", "url": "https://files.pythonhosted.org/packages/8f/eb/74a2fde687c8335419ddfa8239a56c7433a4df30bee1a60c1721594351a3/sqlalchemy_commithooks-1.2.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "506f009b773a2bef84bcff630fe87661", "sha256": "1fcb5746791b45cea2a2556b98860f31f8509926a84695a25260ec04e5ac6576" }, "downloads": -1, "filename": "sqlalchemy_commithooks-1.2.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "506f009b773a2bef84bcff630fe87661", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 7915, "upload_time": "2018-06-26T19:43:29", "url": "https://files.pythonhosted.org/packages/66/c3/02695f707e95740d9acfea4354a271d023c3d2a81195a3d7806807a0557f/sqlalchemy_commithooks-1.2.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "2b39d0c3a3647cfb420c7a6971740f00", "sha256": "14536617d66f08c095f9abd629f205451e8d105d551f6537d0e98c5d5665eb75" }, "downloads": -1, "filename": "sqlalchemy_commithooks-1.2.8.tar.gz", "has_sig": false, "md5_digest": "2b39d0c3a3647cfb420c7a6971740f00", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9133, "upload_time": "2018-06-26T19:43:29", "url": "https://files.pythonhosted.org/packages/8f/eb/74a2fde687c8335419ddfa8239a56c7433a4df30bee1a60c1721594351a3/sqlalchemy_commithooks-1.2.8.tar.gz" } ] }