Skip to content

Conversation

@gabor-lbl
Copy link

@gabor-lbl gabor-lbl commented Oct 30, 2025

Description

I added an optional constructor parameter to always use lists for relationships and not make relay Connections. This way users who don't use Connections don't have to add __use_list__ to every model.

Types of Changes

  • Core
  • Bugfix
  • New feature
  • Enhancement/optimization
  • Documentation

Issues Fixed or Closed by This PR

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes. (Couldn't get tox to run... will continue to look into this)
  • I have tested the changes and verified that they work and don't break anything (as well as I can manage).
    (I'm using it in my project.)

Summary by Sourcery

Add optional always_use_list parameter to StrawberrySQLAlchemyMapper to default relationship fields to lists and bypass Relay Connection creation.

New Features:

  • Introduce always_use_list constructor parameter to always generate lists for relationships instead of Relay Connections

Enhancements:

  • Modify relationship type conversion and resolver logic to respect the always_use_list flag

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 30, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Introduces an always_use_list flag to StrawberrySQLAlchemyMapper allowing users to default to list-based relationship fields instead of relay connections.

File-Level Changes

Change Details Files
Added always_use_list configuration option to the mapper
  • Declared always_use_list attribute with docstring
  • Extended init signature with always_use_list parameter and initialized it to False by default
src/strawberry_sqlalchemy_mapper/mapper.py
Updated relationship conversion logic to respect always_use_list
  • Modified _convert_relationship_to_strawberry_type to use List when always_use_list is true
  • Adjusted connection_resolver_for to bypass connections if always_use_list is enabled
src/strawberry_sqlalchemy_mapper/mapper.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/strawberry_sqlalchemy_mapper/mapper.py:678` </location>
<code_context>
    def connection_resolver_for(
        self, relationship: RelationshipProperty, use_list=False
    ) -> Callable[..., Awaitable[Any]]:
        """
        Return an async field resolver for the given relationship that
        returns a Connection instead of an array of objects.

        This resolver also handles pagination arguments (first, after, last, before) that are
        passed from the GraphQL query to the database query.
        """
        relationship_resolver = self.relationship_resolver_for(relationship)
        if relationship.uselist and not (use_list or self.always_use_list):
            return self.make_connection_wrapper_resolver(
                relationship_resolver,
                relationship,
            )
        else:
            return relationship_resolver

</code_context>

<issue_to_address>
**suggestion (code-quality):** Simplify logical expression using De Morgan identities ([`de-morgan`](https://docs.sourcery.ai/Reference/Default-Rules/refactorings/de-morgan/))

```suggestion
        if relationship.uselist and not use_list and not self.always_use_list:
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@botberry
Copy link
Member

botberry commented Oct 30, 2025

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


Added a new optional constructor parameter to always use lists instead of relay Connections for relationships. Defaults to False, maintaining current functionality. If set to True, all relationships will be handled as lists.

Example:
mapper = StrawberrySQLAlchemyMapper(always_use_list=True)

gabor-lbl and others added 2 commits October 30, 2025 14:17
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
@Ckk3
Copy link
Contributor

Ckk3 commented Oct 31, 2025

Thanks for your contribuition, @gabor-lbl , I hope to review it in this weekend!

Copy link
Contributor

@Ckk3 Ckk3 left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution, @gabor-lbl ☺️!
If you can't find time to do the comments please tell me that I will continue from here.

if relationship.uselist:
# Use list if excluding relay pagination
if use_list:
if use_list or self.always_use_list:
Copy link
Contributor

Choose a reason for hiding this comment

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

todo (blocking)
I think we should create tests to validate this changes, what do you think @gabor-lbl ?

Copy link
Author

Choose a reason for hiding this comment

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

I agree. When I run tox I get an error though:

❯ tox
.pkg: _optional_hooks> python /Users/gtorok/dev/strawberry-sqlalchemy/aaa/lib/python3.9/site-packages/pyproject_api/_backend.py True poetry.core.masonry.api
.pkg: get_requires_for_build_sdist> python /Users/gtorok/dev/strawberry-sqlalchemy/aaa/lib/python3.9/site-packages/pyproject_api/_backend.py True poetry.core.masonry.api
.pkg: get_requires_for_build_wheel> python /Users/gtorok/dev/strawberry-sqlalchemy/aaa/lib/python3.9/site-packages/pyproject_api/_backend.py True poetry.core.masonry.api
.pkg: prepare_metadata_for_build_wheel> python /Users/gtorok/dev/strawberry-sqlalchemy/aaa/lib/python3.9/site-packages/pyproject_api/_backend.py True poetry.core.masonry.api
.pkg: build_sdist> python /Users/gtorok/dev/strawberry-sqlalchemy/aaa/lib/python3.9/site-packages/pyproject_api/_backend.py True poetry.core.masonry.api
default: install_package> python -I -m pip install --force-reinstall --no-deps /Users/gtorok/dev/strawberry-sqlalchemy/.tox/.tmp/package/6/strawberry_sqlalchemy_mapper-0.7.0.tar.gz
default: commands[0]> pytest
default: failed with pytest is not allowed, use allowlist_externals to allow it
.pkg: _exit> python /Users/gtorok/dev/strawberry-sqlalchemy/aaa/lib/python3.9/site-packages/pyproject_api/_backend.py True poetry.core.masonry.api
  default: FAIL code 1 (1.53 seconds)
  evaluation failed :( (1.54 seconds)

Copy link
Author

Choose a reason for hiding this comment

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

I've never used tox or poetry before so please let me know if I'm doing something wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gabor-lbl Dont need to bother with this, if it runs with pytest in your machine you can just push the changes that our CI will setup and run the tests again using nox in every python version we support 😉

Copy link
Author

Choose a reason for hiding this comment

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

What do I need to install to run pytest? I ran pytest on its own and it needed testing.postgres. I installed that but it still won't run:

❯ pytest
ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --emoji --mypy-ini-file=mypy.ini
  inifile: /Users/gtorok/dev/strawberry-sqlalchemy/pyproject.toml
  rootdir: /Users/gtorok/dev/strawberry-sqlalchemy

Copy link
Contributor

Choose a reason for hiding this comment

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

@gabor-lbl Oh you need to have a postgres soo it can create the database.
I recommend you use a devcontainer since it automatically runs a postgres container
, we have one in our project just open your vscode, press f1 and select "Reopen in Container"
image

If you prefer, we can also talk in strawberry discord server, you can find me there as @gustavom0ta

Copy link
Author

Choose a reason for hiding this comment

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

Ok thanks - I added a new test to check the always_use_list param.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @gabor-lbl , I'll review it later

if relationship.uselist:
# Use list if excluding relay pagination
if use_list:
if use_list or self.always_use_list:
Copy link
Contributor

Choose a reason for hiding this comment

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

@gabor-lbl Dont need to bother with this, if it runs with pytest in your machine you can just push the changes that our CI will setup and run the tests again using nox in every python version we support 😉

@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.39%. Comparing base (6bb53b2) to head (ce24580).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #257      +/-   ##
==========================================
+ Coverage   92.31%   92.39%   +0.08%     
==========================================
  Files          19       19              
  Lines        2395     2421      +26     
  Branches      188      188              
==========================================
+ Hits         2211     2237      +26     
  Misses         98       98              
  Partials       86       86              
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 4, 2025

CodSpeed Performance Report

Merging #257 will not alter performance

Comparing gabor-lbl:main (ce24580) with main (6bb53b2)

Summary

✅ 1 untouched

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.

3 participants