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

Binding DB sessions based on SQLAlchemy 1, changing how to declare Base Model classes, and other code modernization #4

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased](https://github.com/python-social-auth/social-app-webpy/commits/master)

### Changed
- Modified model and access code to work with SQLAlchemy version 2 (Issue #1)
- Updated packaging information files per PEP 517, PEP 518 (Issue #2)
- Restricted Python minimum working version to 3.7 or higher to align with SQLAlchemy 2 (Issue #1)
- Fixed behavior of get_current_user function throwing a None error when executed (Issue #3)

## [1.0.0](https://github.com/python-social-auth/social-app-webpy/releases/tag/1.0.0) - 2017-01-22

### Added
Expand Down
8 changes: 2 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
build:
@ python setup.py sdist
@ python setup.py bdist_wheel --python-tag py2
@ BUILD_VERSION=3 python setup.py bdist_wheel --python-tag py3
@ python -m build

publish:
@ python setup.py sdist upload
@ python setup.py bdist_wheel --python-tag py2 upload
@ BUILD_VERSION=3 python setup.py bdist_wheel --python-tag py3 upload
@ twine upload dist/*

clean:
@ find . -name '*.py[co]' -delete
Expand Down
53 changes: 53 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = 'social-auth-app-webpy'
dynamic = ["version"]
dependencies = [
"six",
"social-auth-core>=1.0.0",
"social-auth-storage-sqlalchemy>=1.0.0",
]
authors = [
{name = "Matias Aguirre", email = "[email protected]"},
{name = "Lee Ji-ho", email = "[email protected]"},
]
description = 'Python Social Authentication, web.py integration.'
license = {text = 'BSD'}
keywords = ["web.py", "sqlalchemy", "social auth"]
readme = "README.md"
classifiers=[
'Development Status :: 4 - Beta',
'Topic :: Internet',
'License :: OSI Approved :: BSD License',
'Intended Audience :: Developers',
'Environment :: Web Environment',
'Programming Language :: Python',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12'
]
requires-python = ">= 3.7"

[project.urls]
Repository = 'https://github.com/python-social-auth/social-app-webpy'
Documentation = 'http://python-social-auth.readthedocs.org'
Issues = 'https://github.com/python-social-auth/social-app-webpy/issues'
Changelog = 'https://github.com/python-social-auth/social-app-webpy/blob/master/CHANGELOG.md

[options]
zip_safe = false

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages]
find = {}

[tool.setuptools.dynamic]
version = {attr = "social_webpy.__version__"}
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

36 changes: 0 additions & 36 deletions setup.py

This file was deleted.

1 change: 0 additions & 1 deletion social_webpy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self, *args, **kwargs):
self.strategy = load_strategy()
self.data = web.input(_method=method)
self.backend = None
self._user = None
super(BaseViewClass, self).__init__(*args, **kwargs)

def get_current_user(self):
Expand Down
15 changes: 8 additions & 7 deletions social_webpy/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Flask SQLAlchemy ORM models for Social Auth"""
import web

from sqlalchemy import Column, String, ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import relationship, DeclarativeBase, Mapped, mapped_column
Copy link

Choose a reason for hiding this comment

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

The import statements have been updated to align with SQLAlchemy 2 standards. However, it's important to ensure that DeclarativeBase is correctly imported from sqlalchemy.orm as declarative_base to maintain consistency with SQLAlchemy's expected usage patterns.

- from sqlalchemy.orm import relationship, DeclarativeBase, Mapped, mapped_column
+ from sqlalchemy.orm import relationship, declarative_base, Mapped, mapped_column
+ SocialBase = declarative_base()

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import relationship, DeclarativeBase, Mapped, mapped_column
from sqlalchemy import String, ForeignKey
from sqlalchemy.orm import relationship, declarative_base, Mapped, mapped_column
SocialBase = declarative_base()

from sqlalchemy.ext.declarative import declarative_base

from social_core.utils import setting_name, module_member
Expand All @@ -14,7 +14,8 @@
BaseSQLAlchemyStorage


SocialBase = declarative_base()
class SocialBase(DeclarativeBase):
pass

UID_LENGTH = web.config.get(setting_name('UID_LENGTH'), 255)
User = module_member(web.config[setting_name('USER_MODEL')])
Expand All @@ -28,10 +29,10 @@ def _session(cls):

class UserSocialAuth(WebpySocialBase, SQLAlchemyUserMixin, SocialBase):
"""Social Auth association model"""
uid = Column(String(UID_LENGTH))
user_id = Column(User.id.type, ForeignKey(User.id),
nullable=False, index=True)
user = relationship(User, backref='social_auth')
uid: Mapped[str] = mapped_column(String(UID_LENGTH))
user_id: Mapped[int] = mapped_column(ForeignKey(User.id),
nullable=False, index=True)
user: Mapped["User"] = relationship(User, backref='social_auth')

@classmethod
def username_max_length(cls):
Expand Down