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

Type clash after 2.16.0 upgrade (breaking change in drift_dev) #2919

Open
bbjay opened this issue Mar 12, 2024 · 2 comments
Open

Type clash after 2.16.0 upgrade (breaking change in drift_dev) #2919

bbjay opened this issue Mar 12, 2024 · 2 comments
Labels
bug Something isn't working generator Affects the generator package-drift_dev Affects the drift_dev package

Comments

@bbjay
Copy link

bbjay commented Mar 12, 2024

After upgrading to 2.16.0 I get the following breaking change in the generated database.g.dart:

-class $MessageTable extends Message with TableInfo<$MessageTable, MessageData> {
+class $MessageTable extends m.Message
+    with TableInfo<$MessageTable, MessageData> {
   @override
   final GeneratedDatabase attachedDatabase;
   final String? _alias;

It's working (chooses the right Message type) up to 2.15.0 and I suspect 261c151 to be the breaking change.

My database.dart looks like:

import '../models/message.dart' as m;
import 'tables.dart';
part 'database.g.dart';

@DriftDatabase(tables: [Message])
class Database extends _$Database {

and tables.dart:

class Message extends Table {
  IntColumn get id => integer().autoIncrement()();
}

The following workaround resolves the issue (import with alias, move to top):

import 'tables.dart' as t;
import '../models/message.dart' as m;
part 'database.g.dart';

It looks like types from an alias import is given precedence and imports are order dependent now when generating code.

The fix introduced for #2904 did not resolve this issue (as this is not dart: vs package: related).

@simolus3 simolus3 added bug Something isn't working generator Affects the generator package-drift_dev Affects the drift_dev package labels Mar 12, 2024
@hiroshihorie
Copy link

hiroshihorie commented Mar 30, 2024

I have the same exact issue, I have to use 2.15.0 until resolved...

@simolus3
Copy link
Owner

Can you work around this issue with the import-reordering trick/adding import aliases to all conflicting imports?

Unfortunately we don't have enough information available in the default builder to reliably fix this, but I think I can at least add an option to revert this behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working generator Affects the generator package-drift_dev Affects the drift_dev package
Projects
None yet
Development

No branches or pull requests

3 participants