Skip to content

Commit

Permalink
Upgrade SQLAlchemy (#101)
Browse files Browse the repository at this point in the history
* Upgrade SQLAlchemy

Remove sqlalchemy-dst, update SQLAlchemy.

* Update to compose v2

* Update ci.yml

* Update ci.yml
  • Loading branch information
amCap1712 authored Dec 21, 2024
1 parent be91cbd commit 5566301
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 43 deletions.
23 changes: 7 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,16 @@ jobs:
continue-on-error: true

- name: Pull docker images
run: docker-compose -f test/docker-compose.yml pull

- uses: satackey/[email protected]
continue-on-error: true

run: docker compose -f test/docker-compose.yml pull

- name: Build the Docker image
run: docker-compose -f test/docker-compose.yml -p brainzutils_test build
run: docker compose -f test/docker-compose.yml -p brainzutils_test build

- name: Bring up dependencies
run: docker-compose -f test/docker-compose.yml -p brainzutils_test up -d redis musicbrainz_db
run: docker compose -f test/docker-compose.yml -p brainzutils_test up -d redis musicbrainz_db

- name: Run tests
run: docker-compose -f test/docker-compose.yml -p brainzutils_test run --rm test

- name: Publish Unit Test Results
uses: EnricoMi/[email protected]
if: ${{ always() }}
with:
files: reports/test_results.xml

run: docker compose -f test/docker-compose.yml -p brainzutils_test run --rm test

- name: Bring down containers
run: docker-compose -f test/docker-compose.yml -p brainzutils_test down
run: docker compose -f test/docker-compose.yml -p brainzutils_test down
57 changes: 36 additions & 21 deletions brainzutils/musicbrainz_db/serialize.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
from brainzutils.musicbrainz_db.models import ENTITY_MODELS
from mbdata.utils.models import get_link_target
from sqlalchemy_dst import row2dict


def serialize_begin_end(entity):
begin_date = entity.begin_date
end_date = entity.end_date
begin = []
end = []
if begin_date.year:
if begin_date and begin_date.year:
begin.append(f'{begin_date.year:04}')
if begin_date.month:
begin.append(f'{begin_date.month:02}')
if begin_date.day:
begin.append(f'{begin_date.day:02}')
if end_date.year:

if end_date and end_date.year:
end.append(f'{end_date.year:04}')
if end_date.month:
end.append(f'{end_date.month:02}')
Expand All @@ -33,7 +33,7 @@ def serialize_areas(area, includes=None):
if includes is None:
includes = {}
data = {
'mbid': area.gid,
'mbid': str(area.gid),
'name': area.name,
}

Expand Down Expand Up @@ -68,7 +68,7 @@ def serialize_relationships(data, source_obj, relationship_objs):
for obj in relationship_objs[relation]:
link_data = {
'type': obj.link.link_type.name,
'type-id': obj.link.link_type.gid,
'type-id': str(obj.link.link_type.gid),
'begin-year': obj.link.begin_date_year,
'end-year': obj.link.end_date_year,
}
Expand All @@ -84,7 +84,7 @@ def serialize_artist_credit(artist_credit):
data = []
for artist_credit_name in artist_credit.artists:
artist_credit_data = {
'mbid': artist_credit_name.artist.gid,
'mbid': str(artist_credit_name.artist.gid),
'name': artist_credit_name.artist.name,
}

Expand All @@ -104,7 +104,7 @@ def serialize_recording(recording, includes=None):
if includes is None:
includes = {}
data = {
'mbid': recording.gid,
'mbid': str(recording.gid),
'name': recording.name,
}

Expand Down Expand Up @@ -137,7 +137,7 @@ def serialize_places(place, includes=None):
if includes is None:
includes = {}
data = {
'mbid': place.gid,
'mbid': str(place.gid),
'name': place.name,
'address': place.address,
}
Expand Down Expand Up @@ -170,7 +170,7 @@ def serialize_labels(label, includes=None):
if includes is None:
includes = {}
data = {
'mbid': label.gid,
'mbid': str(label.gid),
'name': label.name,
}

Expand Down Expand Up @@ -200,7 +200,7 @@ def serialize_artists(artist, includes=None):
if includes is None:
includes = {}
data = {
'mbid': artist.gid,
'mbid': str(artist.gid),
'name': artist.name,
'sort_name': artist.sort_name,
}
Expand Down Expand Up @@ -239,7 +239,7 @@ def serialize_release_groups(release_group, includes=None):
includes = {}

data = {
'mbid': release_group.gid,
'mbid': str(release_group.gid),
'title': release_group.name,
}

Expand Down Expand Up @@ -291,12 +291,12 @@ def serialize_medium(medium, includes=None):

def serialize_track(track):
return {
'mbid': track.gid,
'mbid': str(track.gid),
'name': track.name,
'number': track.number,
'position': track.position,
'length': track.length,
'recording_id': track.recording.gid,
'recording_id': str(track.recording.gid),
'recording_title': track.recording.name,
'artist-credit': [serialize_artist_credit_names(artist_credit_name)
for artist_credit_name in track.recording.artist_credit.artists],
Expand All @@ -309,7 +309,7 @@ def serialize_releases(release, includes=None):
includes = {}

data = {
'mbid': release.gid,
'mbid': str(release.gid),
'name': release.name,
}

Expand Down Expand Up @@ -340,7 +340,7 @@ def serialize_events(event, includes=None):
if includes is None:
includes = {}
data = {
'mbid': event.gid,
'mbid': str(event.gid),
'name': event.name,
}

Expand All @@ -366,7 +366,7 @@ def serialize_url(url, includes=None):
if includes is None:
includes = {}
data = {
'mbid': url.gid,
'mbid': str(url.gid),
'url': url.url,
}

Expand All @@ -379,7 +379,7 @@ def serialize_works(work, includes=None):
if includes is None:
includes = {}
data = {
'mbid': work.gid,
'mbid': str(work.gid),
'name': work.name,
}

Expand All @@ -399,10 +399,25 @@ def serialize_works(work, includes=None):


def serialize_editor(editor, includes=None):
data = row2dict(editor, exclude_pk=True, exclude={'password', 'ha1'})

# TODO: Add includes to data here (BU-18)

data = {
"id": editor.id,
"name": editor.name,
"privs": editor.privs,
"email": editor.email,
"website": editor.website,
"bio": editor.bio,
"member_since": editor.member_since,
"email_confirm_date": editor.email_confirm_date,
"last_login_date": editor.last_login_date,
"last_updated": editor.last_updated,
"birth_date": editor.birth_date,
"deleted": editor.deleted,
"gender": editor.gender,
"area": None
}
if editor.area:
data["area"] = serialize_areas(editor.area)
return data


Expand All @@ -411,7 +426,7 @@ def serialize_series(series, includes=None):
includes = {}

data = {
'mbid': series.gid,
'mbid': str(series.gid),
'name': series.name,
}

Expand Down
21 changes: 21 additions & 0 deletions brainzutils/musicbrainz_db/tests/test_serialize.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import datetime, date

from brainzutils.musicbrainz_db.serialize import serialize_recording, serialize_artist_credit, serialize_editor
from brainzutils.musicbrainz_db.test_data import recording_numb_encore_explicit, artistcredit_jay_z_linkin_park, \
editor_2
Expand Down Expand Up @@ -67,3 +69,22 @@ def test_serialize_editor(self):
editor = serialize_editor(editor_2)
self.assertNotIn("password", editor)
self.assertNotIn("ha1", editor)
self.assertEqual(editor, {
'id': 2324,
'name': 'Editor 2',
'privs': 3,
'email': '[email protected]',
'website': 'example.com',
'bio': 'Random\neditor',
'member_since': datetime(2014, 12, 1, 14, 6, 42, 321443),
'email_confirm_date': datetime(2014, 12, 1, 14, 6, 42, 321443),
'last_login_date': datetime(2014, 12, 1, 14, 6, 42, 321443),
'last_updated': datetime(2014, 12, 1, 14, 6, 42, 321443),
'birth_date': date(1999, 1, 1),
'deleted': False,
'gender': None,
'area': {
"mbid": "4479c385-74d8-4a2b-bdab-f48d1e6969ba",
"name": "Hämeenlinna"
}
})
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ Jinja2>=3.0
itsdangerous>=2.0
click>=8.0
Werkzeug>=2.0
Flask-DebugToolbar>=0.13.1
Flask-DebugToolbar@git+https://github.com/amCap1712/flask-debugtoolbar.git@f42bb238cd3fbc79c51b93c341164c2be820025e
Flask-UUID>=0.2
sentry-sdk[flask]>=1.5.8
certifi
redis>=4.2.2
msgpack==0.5.6
requests>=2.27.1
SQLAlchemy>=1.3.16,<2.0
SQLAlchemy>=2.0
mbdata@git+https://github.com/acoustid/[email protected]
sqlalchemy-dst>=1.0.1
importlib-metadata>=3.10.0;python_version<'3.10'
14 changes: 11 additions & 3 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ fi
COMPOSE_FILE_LOC=test/docker-compose.yml
COMPOSE_PROJECT_NAME=brainzutils_test

echo "Checking docker compose version"
if docker compose version &> /dev/null; then
DOCKER_COMPOSE_CMD="docker compose"
else
DOCKER_COMPOSE_CMD="docker-compose"
fi

function invoke_docker_compose {
docker-compose -f $COMPOSE_FILE_LOC \
-p $COMPOSE_PROJECT_NAME \
"$@"
$DOCKER_COMPOSE_CMD \
-f $COMPOSE_FILE_LOC \
-p $COMPOSE_PROJECT_NAME \
"$@"
}

function docker_compose_run {
Expand Down

0 comments on commit 5566301

Please sign in to comment.