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

SQLAlchemy rewrite #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RustyBower
Copy link
Contributor

No description provided.

@RustyBower
Copy link
Contributor Author

I wasn't sure what to do with the requirements file, so please test this out and let me know what I should pin sopel versions to...

This should work with any version of sopel, but please confirm my suspicions :)

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

tl;dr: sopel.db.engine isn't technically part of the API, and shouldn't be used directly by plugins.

sopel_modules/github/webhook.py Outdated Show resolved Hide resolved
sopel_modules/github/github.py Outdated Show resolved Hide resolved
@dgw dgw added the bugfix label Nov 6, 2019
@dgw
Copy link
Member

dgw commented Nov 6, 2019

This should work with any version of sopel

I doubt it. Sopel before 7.0 (current master there) uses SQLite3 directly, not SQLAlchemy, so a lot of this stuff probably won't work properly. Just bump the requirements to sopel>=7.0,<8 like you did for the YouTube plugin.

@RustyBower RustyBower force-pushed the sopel_7_fixes branch 2 times, most recently from f621e54 to ebdf786 Compare November 7, 2019 15:55
@RustyBower
Copy link
Contributor Author

Refactored all the database connectivity things.

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

I see some issues with consistency. Seems to be very confusing naming variables engine if they actually hold Connection objects?

Also, the repeated try/except for getting a DB session could probably stand to get abstracted out into a function. Maybe a function that takes a Sopel (bot) object and returns the session (or raises an exception if it can't get one)?

I was really hoping to avoid importing SQLAlchemy into this project, but I get the impression that we have to unless the DB object API in Sopel itself gets fleshed out a ton.

print("OperationalError: Unable to connect to database.")
raise

session = scoped_session(sessionmaker(bind=engine))
Copy link
Member

Choose a reason for hiding this comment

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

Sometimes you use engine, sometimes engine.engine. Are you sure about this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weirdly it works both ways lol

@RustyBower
Copy link
Contributor Author

The colors don't translate into GH comments, but I promise they still look fabulous.

05:24:24 <sopel> Successfully enabled listening for rustybower/test's events in #bottest.
05:24:24 <sopel> Great! Please allow me to create my webhook by authorizing via this link: https://git.io/Jea5L
05:24:25 <sopel> Once that webhook is successfully created, I'll post a message in here. Give me about a minute or so to set it up after you authorize. You can configure the colors that I use to display webhooks with .gh-hook-color
05:25:30 <sopel> [test] RustyBower: It's not fully shipped until it's fast. (Your webhook is now enabled)
05:27:51 <sopel> [test] RustyBower pushed 1 new commit to master https://git.io/JeVu4
05:27:52 <sopel> test/master 335e2ae Rusty Bower: testing
05:28:00 <@RustyCloud> .gh-hook-color rustybower/test 1 2 3 4 5 6
05:28:00 <sopel> [rustybower/test] Example name: RustyCloud tag: tag commit: c0mm17 branch: master url: https://git.io/
05:28:21 <sopel> [test] RustyBower pushed 1 new commit to master https://git.io/JeVuB
05:28:21 <sopel> test/master 441cae1 Rusty Bower: testing

@dgw
Copy link
Member

dgw commented Nov 9, 2019

Why is the same identical function defined twice? Not to nitpick too much, but that seems very silly. Even sillier than the fact that setup_webhook() still has dedicated DB-connection code… which is kind of on me, because I mentioned sessions and that doesn't need one. 😆

The colors don't translate into GH comments

Indeed, the relative lack of formatting options here vs. on IRC caught me out when trying to write nice PR descriptions for additions to sopel.tools.formatting a while back.

Copy link
Member

@dgw dgw left a comment

Choose a reason for hiding this comment

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

Not doing a full-on review, but there's one thing I noticed (line-noted). Also, should this not use a similar approach to Sopel's own DB class for thread-safety? That is, with regard to the scoped session management approach you proposed in sopel-irc/sopel#1755.

Comment on lines +125 to +132
def get_db_session(bot):
try:
engine = bot.db.connect()
except OperationalError:
print("OperationalError: Unable to connect to database.")
raise

return scoped_session(sessionmaker(bind=engine))
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this pulled in from .utils now?

@dgw
Copy link
Member

dgw commented Jan 30, 2020

It's no longer necessary to make any changes just to make this plugin keep working—tweaks to Sopel's database API mean this and other plugins that use direct DB access with Sopel 6.x will continue to work with 7.x if the default SQLite database backend is in use.

That said, we should still migrate onto SQLAlchemy eventually. It'll give this plugin compatibility with more database types, and as more upstream users take advantage of the new supported backends the restriction to using this plugin with SQLite will become more onerous.

@dgw dgw added enhancement and removed bugfix labels Jan 30, 2020
@dgw dgw changed the title github: sopel 7 fixes SQLAlchemy rewrite Jan 30, 2020
@dgw dgw modified the milestones: 0.3.0, 0.4.0 Jan 30, 2020
@dgw dgw modified the milestones: 0.4.0, 0.5.0 Oct 19, 2020
@dgw dgw modified the milestones: 0.5.0, 0.6.0 Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants