Closed erikwrede closed 1 year ago
Base: 96.24% // Head: 96.34% // Increases project coverage by +0.09%
:tada:
Coverage data is based on head (
3923322
) compared to base (a03e74d
). Patch coverage: 96.71% of modified lines in pull request are covered.
:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
@sabard All fixed up, feel free to merge if nothing else comes up :)
I've had regression in my code after upgrading graphene-sqlalchemy and it just by reading the changes one by one that I saw these breaking changes. I'd like to suggest such breaking changes to be indicated in the release notes otherwise they are hard to find.
@guillaumep sorry about that, it seems like the release notes for this release were not published properly. We will fix that up soon.
As a tip: in the change list, we will use semantic commits in the future, and in the notes of this release, this PR was already marked with a !
, which suggests a breaking change. Of course I acknowledge that this should not be the only information, and as you've seen from the other release notes, we usually publish more detailed information. For the 3.0 full release, there will be a full upgrade guide.
Apart from that, how is this change working for you? We haven't received too much feedback yet, so I'd love to hear your thoughts.
sorry about that, it seems like the release notes for this release were not published properly. We will fix that up soon.
Don't worry about it, and thanks for listening to my feedback.
As a tip: in the change list, we will use semantic commits in the future, and in the notes of this release, this PR was already marked with a
!
, which suggests a breaking change.
I was not completely aware of this convention in open source projects. I'll pay more attention to it starting now.
For the 3.0 full release, there will be a full upgrade guide.
Great!
Apart from that, how is this change working for you? We haven't received too much feedback yet, so I'd love to hear your thoughts.
I upgraded from 3.0.0b3 to 3.0.0b4. Once I figured out how to change my code everything worked pretty well. We register a custom multi lingual dictionary SQLAlchemy type, which serializes data to a string in the database. We are providing the data as an object to the API clients. Here's the code diff for the upgrade:
from graphene_sqlalchemy.converter import convert_sqlalchemy_type
+from graphene_sqlalchemy.utils import column_type_eq
-@convert_sqlalchemy_type.register(ModelMlText)
+@convert_sqlalchemy_type.register(column_type_eq(ModelMlText))
def convert_mltext_to_json(type, column, registry=None):
return MlText
The key here was to figure-out the use of column_type_eq
. I read graphene-sqlalchemy's source code to see existing examples to figure this one out.
Thanks for the ongoing work on the project!
This PR refactors the type conversion system to use the same converters for all column types (column + hybrid). Previously, we had
convert_sqlalchemy_column
usingsingledispatch
andconvert_sqlalchemy_hybrid_property_type
using a custom singledispatch-like solution to match column and hybrid property type(-hints) to their graphene equivalents. This implied having to maintain two separate type conversion systems with very similar functionality. This PR proposes merging the systems based on our custom singledispatch-style approach. This has several implications:Breaking Change: convert_sqlalchemy_type now uses a matcher function
Our custom matcher needs to be able to check more than just the type of a column. Some type hints like unions or optionals need further processing. To convert old singledispatch-style converters to the new converters, the column type has to be wrapped in our custom
value_equals
helper function:Breaking Change: convert_sqlalchemy_type support for subtypes is dropped, each column type must be explicitly registered
Since we now use matcher functions, it doesn't make sense to check if any inherited types match the singledispatch converters, as they might interfere with other matchers. Because of that, all types must now be explicitly registered:
See
converter.py
for more detailed examples.Breaking Change: The first argument to converter functions is always a type
Previously, both type and instances of types were passed to the converter. (
String
vsString(30)
). If you need information from the instance, usecolumn.type
instead. Remember to check ifcolumn
is present and not ahybrid_property
Example:
Breaking Change: convert_sqlalchemy_type's column and registry arguments must now be keyword arguments
To make additional support for type conversions possible, we converted all arguments to the converters to keyword arguments. It is not guaranteed for these to be present, so you should always check for existance of
column
orregistry
if you plan on using them. Since other arguments might be provided as well, make sure that**kwargs
is present on your signature and that it is passed to any calls of nested type conversions (e.g.List[JSON]
callsconvert_list
, thenconvert_list
starts another conversion for the inner type)Breaking Change: The hybrid property default column type is no longer a string. If no matching column type was found, an exception will be raised.
We introduced warnings for the string fallback in
3.0.0b2
as a soft transition to the new system. Since we merged both conversion systems, it is impractical to have a fallback for all types. If you want to keep the oldstring
types for your hybrids, please use: